我想向粗體添加(參見插圖)。如果我這樣做:JavaScript將粗體文本添加到框架
p:function{
sel = this.getSelection().getRangeAt(0);
var caretPosition = sel.endOffset;
var existingText = this.iframe[0].contentWindow.document.body.innerText;
var before = existingText.substring(0, caretPosition);
var after = existingText.substring(caretPosition);
this.iframe[0].contentWindow.document.body.innerHTML= before
+'**<b>**(see illustration)**</b>** ' + after;
},
然後我寫的所有文本(請參閱插圖變成粗體)。
['的execCommand()'] (https://developer.mozilla.org/en-US/docs/Web/API/document.execCommand )可能有幫助? – Teemu