为什么 execCommand('bold') 什么都不做?

Why Does execCommand('bold') Do Nothing?

我正在尝试制作一个简单的 WYSIWYG 编辑器,但我无法将文本设为粗体。我可以用 document.execCommand("underline", false, null); 为文本加下划线,用 document.execCommand("italic", false, null); 使文本为斜体,但 document.execCommand("bold", false, null); 什么都不做。

我检查了 html 输出,它也没有向文本添加任何 <b><strong> 标签。

这是HTML:

<button id="underline" type="button">Underline</button>
<button id="italic" type="button">Italic</button>
<button id="bold" type="button">Bold</button>
<div id="editor" contenteditable="true" spellcheck="false"></div>

这里是 jQuery:

$('#underline').click(function() {
   document.execCommand("underline", false, null);
});

$('#italic').click(function() {
   document.execCommand("italic", false, null);
});

$('#bold').click(function() {
   document.execCommand("bold", false, null);
});

据我所知,这是有效的。看看这个 fiddle:http://jsfiddle.net/om78patL/

$('#underline').click(function() {
   document.execCommand("underline", false, null);
});

$('#italic').click(function() {
   document.execCommand("italic", false, null);
});

$('#bold').click(function() {
   document.execCommand("bold", false, null);
});

<button id="underline" type="button">Underline</button>
<button id="italic" type="button">Italic</button>
<button id="bold" type="button">Bold</button>
<div id="editor" contenteditable="true" spellcheck="false">test</div>