2013-01-22 32 views
1

我加载HTML到一系列textareas,我给一种风格的显示:无; 然后我有一个很好的下拉菜单,选项包含每个textarea的ID属性的值。TinyMCE - 从其他Textareas加载Html

我有jquery监听下拉列表的变化,当检测到ID时,我用可爱的TinyMCE插件将相应的textarea的值加载到主textarea中。

这一切工作正常,没有TinyMCE。但编辑器不会显示动态加载的html文本。

任何人都可以看到我做错了什么?

代码:

<textarea id="template1"><div>Some html <b>inside this textarea</b><br>And more</textarea> 
<textarea id="template2"><div>More html <b>inside this textarea</b><br>And more</textarea> 

<select name="templateid" id="templateid"> 
    <option value="0">-------------</option> 
    <option value="1">Load Template 1</option> 
    <option value="2">Load Template 2</option> 
</select> 

<textarea id="maintemplate"></textarea> 

<script language="javascript" type="text/javascript"> 
$(document).ready(function(){ 

$("#templateid").change(function(){ 
    var templateid = $(this).val(); 
    if(templateid == 0){ $("#templatetext").val(""); return false; } 
    var html = $("#template"+templateid).val(); 
    $("#maintemplate").val(html); // this is ignored? 
    return false; 
}); 


$("textarea#maintemplate").tinymce({ 
    script_url : '/includes/modules/tiny_mce/tiny_mce.js',// Location of TinyMCE script 
    // General options 
    theme : "advanced", 
    plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist", 
    force_p_newlines : false, 
    force_br_newlines : true, 
    /*forced_root_block : '',*/ 
    // Theme options 
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleprops,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,removeformat,code,|,cleanup,preview", 
    theme_advanced_buttons2 : "", 
    theme_advanced_buttons3 : "", 
    theme_advanced_buttons4 : "", 
    theme_advanced_toolbar_location : "top", 
    theme_advanced_toolbar_align : "left", 
    theme_advanced_statusbar_location : "bottom", 
    theme_advanced_resizing : true, 
}); 

}); 
</script> 

你会看到:$("#maintemplate").val(html);就是我加载其他文本域的值。但编辑只是不显示它。 (没有编辑器,它的工作原理)

+0

不是正面的,但我认为像'tinyMCE.activeEditor.setContent(html);'代替'$(“#maintemplate”)。val(html);' ' –

回答

1

任何人都可以看到我做错了什么?

这里是工作的代码(粘贴,因为它是)的DEMO ....

我可以指出的唯一的事情是,你不加载

<script type="text/javascript" src="../jscripts/tiny_mce/jquery.tinymce.js"></script> 

希望它有助于!