我想清除tinymce內容並添加新內容。我嘗試使用下面的代碼,但它被添加到舊內容。如何從tinymce中清除現有的內容。Tinymce content clear mceCleanup
tinymce.activeEditor.execCommand('mceCleanup');
tinymce.activeEditor.execCommand('mceInsertContent', false, result.content);
我想清除tinymce內容並添加新內容。我嘗試使用下面的代碼,但它被添加到舊內容。如何從tinymce中清除現有的內容。Tinymce content clear mceCleanup
tinymce.activeEditor.execCommand('mceCleanup');
tinymce.activeEditor.execCommand('mceInsertContent', false, result.content);
TinyMCE提供了一個方法setContent。使用此方法設置新值。
tinymce.activeEditor.setContent("content");
類似地,提供的getContent()
tinymce.activeEditor.getContent();
要清除現有的內容,嘗試
tinyMCE.activeEditor.setContent("");
,然後使用相同的setContent()
方法添加所期望的內容:
tinyMCE.activeEditor.setContent(result.content);
有一個已知bug與此,它失去焦點的文本區域,但一個解決辦法是把這個設置或初始化回調的WebKit:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
setup : function(ed) {
if(tinymce.isWebKit) {
//workaround for Webkit to fix focus problems when setting contents to an empty string
ed.onSetContent.add(function() {
window.focus();
ed.focus();
});
}
}
});
文檔有時候太全面了,無法理解.. !! – Fr0zenFyr
@ Fr0zenFyr:如果是這樣,請向我解釋'不同的清理規則選項'這些選項在哪裏列出? – jimasun
@jimasun:我相信你還沒有看過在答案中鏈接的文檔頁面......列出了很多清楚的例子來解釋「不同的清理規則」。 – Fr0zenFyr