我正在尝试将TinyMCE WYSIWYG编辑器添加到我的textareas。
我有一张td
的表格,用户可以点击.load
表格,其中包含输入字段,标签,文字等。
我的td
看起来像这样:
<a href="#" id="display_info" onclick="displayFacilityInformation(61)">Something</a>
displayFacilityInformation()
看起来像这样:
function displayFacilityInformation (facID){
$("#facility_details").load("facilitydetails.php?q="+facID);
$('#facility_details_wrapper').show();
$("#newaccount_form, #newuser_form, #newfacility_form, #accounts, #facilities, #new_section_form").hide(); //hide other divs
//tinymce.EditorManager.execCommand('mceAddEditor',true, general_facility_info); //gave me console error "general_facility_info is undefined")
//tinyMCE.execCommand('mceAddEditor', true, 'general_facility_info');
//tinymce.init({
//selector: "textarea"
//});
//tinyMCE.execCommand('mceAddEditor', true, 'body');
};
我尝试过的各种事情都被注释掉了。 (general_facility_info
是其中一个textareas的ID)
facilitydetails.php
将一个HTML表单输出到div id="facility_details"
,其中包含我希望成为tinyMCE编辑器的textarea。
我的控制台没有抛出任何错误,我能够创建其他(隐藏)形式的其他textareas编辑器。
是否与使用Jquery .load
添加元素有关?
如何制作新添加的textarea的tinyMCE编辑器?
答案 0 :(得分:0)
您正在异步加载此数据。你需要运行init方法作为load
函数运行完成时的回调,否则它会在textareas可能已加载且没有任何反应之前运行。
查看我链接到的文档,其中第三个可选参数是:
完整 类型:Function(String responseText,String textStatus,jqXHR jqXHR) 请求完成时执行的回调函数。
所以你的方法看起来应该更像:
function displayFacilityInformation (facID){
$("#facility_details").load("facilitydetails.php?q="+facID, function() {
$('#facility_details_wrapper').show();
$("#newaccount_form, #newuser_form, #newfacility_form, #accounts, #facilities, #new_section_form").hide(); //hide other divs
tinymce.init({
selector: "textarea"
});
});
};