首页 > 代码库 > 富文本编辑器开发
富文本编辑器开发
<body onl oad="def()"> <div style="width:500px; text-align:left; margin-bottom:10px "> <input type="button" id="bold" style="height:21px; width:21px; font-weight:bold;" value=http://www.mamicode.com/"B" />>接下来添加iframe:<iframe id="textEditor" style="width:500px; height:170px;"> </iframe>编写js代码:
<script type="text/javascript"> <!-- textEditor.document.designMode="on"; textEditor.document.open(); textEditor.document.write('<head><style type="text/css">body{ font-family:arial; font-size:13px;}</style></head>'); textEditor.document.close();这里主要是给iframe的body添加样式,下面是命令函数,比如改变字体大小颜色之类都要通过它来实现:
function fontEdit(x,y) { textEditor.document.execCommand(x,"",y); textEditor.focus(); }
添加各种编辑用的按钮和下拉框:<input type="button" id="bold" style="height:21px; width:21px; font-weight:bold;" value=http://www.mamicode.com/"B" onClick="fontEdit('bold')" />><select id="fonts" onChange="fontEdit('fontname',this[this.selectedIndex].value)"> <option value=http://www.mamicode.com/"Arial">Arial>
下面是整个完整的代码:<html> <head> </head> <body onl oad="def()"><center> <div style="width:500px; text-align:left; margin-bottom:10px "> <input type="button" id="bold" style="height:21px; width:21px; font-weight:bold;" value=http://www.mamicode.com/"B" onClick="fontEdit('bold')" />>
富文本编辑器开发
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。