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');
精彩评论