87,907
社区成员
发帖
与我相关
我的任务
分享
function fn_change_forecolor()
{
//指定前景色
document.execCommand('ForeColor',true,'#FF0000');//true或false都可以
document.execCommand('Bold');
document.execCommand('FontSize',false,4); //true或false都可以
//指定背景色
//字体必须是系统支持的字体
//document.execCommand('FontName',false,'标楷体'); //true或false都可以
//字体变粗
//变斜体
//document.execCommand('Italic');
}
<div id="frame1" contenteditable="true"></div>
<input type="button" id="btnBold" value="加粗"/>
</body>
<script type="text/javascript">
document.getElementById("btnBold").onclick=function(){
document.execCommand("Bold");
}
</script>