简体   繁体   English

动态将TinyMCE编辑器添加到文本框

[英]Dynamically adding TinyMCE editor to textbox

I am adding textboxes dynamically to a div. 我正在向div动态添加文本框。 Something likhe this 像这样的东西

$('#xyz').click(function()
{
     $(#myDiv).append('<textarea></textarea>');
});

Now I want to attach tinymce editor to these textareas, Can you help me in doing this? 现在,我想将tinymce编辑器附加到这些文本区域,您能帮助我做到这一点吗?

Try this: 尝试这个:

$('#xyz').click(function() {
    var myTextarea = $("<textarea></textarea>");
    myTextarea.attr("id", "mce-editor");
    $("#myDiv").append(myTextarea);

    // this inistalises the TinyMCE editor upon the element with the id in the last parameter.
    tinyMCE.execCommand("mceAddControl", false, "mce-editor");
});

You could even attach the tinymce element to the div directly, because you don't need a textarea in order to edit and submit text using a tinymce editor instance. 您甚至可以直接将tinymce元素附加到div,因为您不需要文本区域即可使用tinymce编辑器实例编辑和提交文本。 Tinymce will create an editable iframe in the dom in which the user is able to edit html content. Tinymce将在dom中创建一个可编辑的iframe,用户可以在其中编辑html内容。 OnSave the editors content gets written back to the html element the tinymce editor was created for (this can be a textarea, a div, a paragraph or another html elment). OnSave编辑器的内容将写回到为tinymce编辑器创建的html元素(可以是textarea,div,段落或其他html元素)。

tinyMCE.execCommand('mceAddControl', false, 'myDiv'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM