![](/img/trans.png)
[英]document.execCommand of insertText not working in IE
[英]document.execCommand not working in Firefox and IE
我正在尝试为我的 textarea 设置一些粗体、斜体和下划线按钮,我正在使用此代码从正常切换到粗体/斜体/下划线。
document.execCommand("bold", false, "");
它在 Chrome 中完美运行,但在 Firefox 中,即它不会将文本更改为粗体或任何内容,我不知道为什么?
这是完整的代码:
<input name="new_shout_bold" type="button" class="new_shout_text_option" id="new_shout_bold" onclick='document.execCommand("bold", false, "");' value="B" alt="B" />
<input name="new_shout_italic" type="button" class="new_shout_text_option" onclick='document.execCommand("italic", false, "");' value="I" alt="I" style="font-style: italic;"/>
<input name="new_shout_underline" type="button" class="new_shout_text_option" onclick='document.execCommand("underline", false, "");' value="U" alt="U" style="text-decoration: underline;" />
这是文本区域:
<div id="dash_new_shout_textarea" name="dash_new_shout_textarea" class="dash_new_shout_textarea" contenteditable="true"></div>
有什么想法吗?
通过向 HTML 标记添加unselectable="on"
使按钮在 IE 中unselectable="on"
。
我知道这不会有太大帮助,但此代码在 Chrome 和 Firefox 中运行良好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.