#open_dialog
上的点击事件会触发jQuery UI对话框,其中包含对/ajax/request/url/
我想在ajax请求发回的textarea上发起Tinymce。
使用以下代码我得到日志消息“ajax done!”每次我点击#open_dialog
(并完成ajax请求),但只在第一次打开对话框时加载Tinymce。怎么会?每次加载对话框时如何启动tinymce?
$('#open_dialog').click(function() {
$.when($.ajax("/ajax/request/url/")).done(function() {
console.log("ajax done!");
tinymce.init({selector:"textarea",
toolbar: "undo redo cut copy paste | bold italic underline | bullist numlist | table | styleselect | removeformat ",
plugins: "paste, table",
paste_word_valid_elements: "b,strong,i,em,h1,h2,table,tr,td,th",
menubar: false,
statusbar: true,
resize: "both"
});
});
});
答案 0 :(得分:2)
最后通过删除旧的DOM和旧编辑器来解决它。下面的ee_body
是textarea的DOM ID。
$(document).ready(function() {
tinymce.init({
mode:"none",
toolbar: "undo redo cut copy paste | bold italic underline | bullist numlist | table | styleselect | removeformat ",
plugins: "paste, table",
paste_word_valid_elements: "b,strong,i,em,h1,h2,table,tr,td,th",
menubar: false,
statusbar: true,
resize: "both"
});
});
$('#open_dialog').click(function(){
//Remove old editors and DOM-elements
tinymce.EditorManager.execCommand("mceRemoveEditor", false, "ee_body");
$('#ee_body').remove();
// When ajax request to new email is done, load Tinymce
$.when($.ajax("/ajax/request/url/")).done(function() {
tinyMCE.execCommand("mceAddEditor", true, "ee_body");
});
});