简体   繁体   中英

Dynamically adding TinyMCE editor to textbox

I am adding textboxes dynamically to a 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?

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 will create an editable iframe in the dom in which the user is able to edit html content. 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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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