jQuery 将 tinymce 动态添加到新的 textarea
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9091619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add tinymce to new textarea dynamically
提问by Luciuz
How can i do this
我怎样才能做到这一点
function addTinyText(id, text){
//add textarea to DOM
$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');
//init tineMCE
tinyMCE.init({
theme : "advanced",
plugins : "emotions,spellchecker"
});
//add tinymce to this
tinyMCE.execCommand("mceAddControl", false, 'txt'+id);
}
but as a result every time we have a new textarea+tinyMCE but no text inside
但结果是每次我们有一个新的 textarea+tinyMCE 但里面没有文字
What do i wrong?
我怎么了?
采纳答案by Luciuz
line
线
$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');
should be line
应该是线
$('<textarea id="txt'+id+'"></textarea>').text(text).appendTo('body');
回答by Dieter Gribnitz
I searched a very long time to find an answer to a similar problem.
我搜索了很长时间才能找到类似问题的答案。
My content was not being posted even thou I could get the editor to appear.
即使我可以让编辑出现,我的内容也没有发布。
I got it working like this:
我让它像这样工作:
jQuery('.wysiwyg').tinymce({
// Location of TinyMCE script
script_url : 'path/tinymce/tiny_mce.js',
// General options
theme : "advanced",
.........
.........
......... etc
I used the standard jquery code to initiate all text areas with class name wysiwyg as tinymce objects.
我使用标准的 jquery 代码将类名 wysiwyg 的所有文本区域初始化为 tinymce 对象。
After ajax call completes and new textarea is loaded I run this function:
在 ajax 调用完成并加载新的 textarea 后,我运行此函数:
jQuery(".wysiwyg").each(function(){
tinyMCE.execCommand("mceAddControl",false, this.id);
});
Now my code is finally being posted correctly.
现在我的代码终于被正确发布了。