简体   繁体   English

document.execCommand 在 Firefox 和 IE 中不起作用

[英]document.execCommand not working in Firefox and IE

I am trying to setup some bold, italic and underline buttons for my textarea, I am using this code to make the switch from normal to bold/italic/underline.我正在尝试为我的 textarea 设置一些粗体、斜体和下划线按钮,我正在使用此代码从正常切换到粗体/斜体/下划线。

document.execCommand("bold", false, "");

It works perfect in Chrome, but in Firefox and ie it doesn't change the text to bold or anything and I cannot work out why?它在 Chrome 中完美运行,但在 Firefox 中,即它不会将文本更改为粗体或任何内容,我不知道为什么?

Here is the full code:这是完整的代码:

<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;" />

Here is the textarea:这是文本区域:

<div id="dash_new_shout_textarea" name="dash_new_shout_textarea" class="dash_new_shout_textarea" contenteditable="true"></div>

Any Ideas?有什么想法吗?

通过向 HTML 标记添加unselectable="on"使按钮在 IE 中unselectable="on"

I know this won't help too much, but this code works perfectly fine in Chrome and Firefox我知道这不会有太大帮助,但此代码在 Chrome 和 Firefox 中运行良好

http://jsbin.com/iluXOGe/2/edit http://jsbin.com/iluXOGe/2/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM