【发布时间】:2012-04-09 13:04:49
【问题描述】:
我已经像这样初始化 tinyMCE:
$('#text').tinymce({
// Location of TinyMCE script, optional, already loaded in page.
script_url : '../adminContent/js/tiny_mce/tiny_mce.js',
// General options
theme : "advanced",
plugins : "table,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,visualchars",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,removeformat,cleanup,code,|,preview,tablecontrols,|,hr,visualaid,|,charmap,iespell",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true
});
上面的代码完美运行。问题是当我尝试删除 tinyMCE 时。
我的删除代码是:
$('#text').tinymce().execCommand('mceRemoveControl', false, 'text');
我也试过了:
$('#text').remove();
和
$('#text').tinymce().remove();
第一个似乎没有做任何事情。最后两个给我这个错误:
Uncaught ReferenceError: t is not defined
虽然 HTML 文档加载了 tinymce,但我正在加载另一个脚本:
$.getScript(viewPath + '/mod/adminContent/js/editContent.js', function(){
initEditContent(popup);
});
popup 是对加载 tinymce 的弹出窗口的引用。它只是一个使用 jquery 创建的 div。使用 jquery ajax 加载 div 的内容。
editContent.js 看起来像这样:
var contentID;
function initEditContent(popup){
contentID = $('#contentID').val();
tinyMCE.execCommand("mceAddControl", true, 'text');
setTimeout(reposition, 50);
setTimeout(reposition, 150);
setTimeout(reposition, 250);
// Submit form
$('#editTextForm').ajaxForm(
{
// Before submit
beforeSubmit: function(){
//setPopupMessage(popup, '<div id="loading"><img src="../../img/loading.gif" /> Please wait...</div>');
},
// Once submit completed
success: function(responseText){
tinyMCE.execCommand("mceRemoveControl", true, 'text');
//closePopup(popup);
// Update button with new data
$('#' + contentID).html(responseText);
}
});
}
【问题讨论】:
-
.tinymce().remove()应该可以解决问题。你可以在jsFiddle 上发布一个测试用例,在那里你的问题被重现了吗? -
我已经编辑了我最初的问题,以便为您提供更多详细信息。恐怕无法使用 jsFiddle,因为需要的外部部件太多。
-
调用 tinyMCE.remove();它给出了一个错误:“Uncaught TypeError: Cannot read property 'id' of undefined”在 tiny_mce_src.js 的第 11264 行
-
于是我尝试了 tinyMCE.remove('text') ,它确实有效!但是 - 然后我尝试使用相同的 textarea 加载相同的弹出窗口,它不再初始化 tinyMCE。