如何使用 jquery 将 html 加载到 TinyMCE 文本区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1582251/
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
How to load html using jquery into a TinyMCE textarea
提问by user191687
I've a textarea that uses TinyMCE as a WYSIWYG. Once that this textarea is loaded I want that, clicking a button "Edit" some html code that I bring with AJAX jquery is loaded in that textarea.
我有一个使用 TinyMCE 作为所见即所得的 textarea。一旦加载了这个textarea,我想要那个,点击一个按钮“编辑”我用AJAX jquery带来的一些html代码被加载到那个textarea中。
I want to insert this html code <p>hello</p>
我想插入这个html代码 <p>hello</p>
Original textarea source
原始文本区域源
<textarea name="corpo" id="input_corpo">Text Here</textarea>
JQUERY Script that brings the HTML. In this way it updates only the textarea (which is hidden while TinyMCE is in action)
带来 HTML 的 JQUERY 脚本。通过这种方式,它只更新 textarea(在 TinyMCE 运行时隐藏)
$.get("hello.html",
function(content){ $("#input_corpo").text(content);});
return false;});
Neither in this way below it works. I tryed to update the body of the iframe that generates TinyMCE
在它下面的这种方式都不起作用。我尝试更新生成 TinyMCE 的 iframe 的主体
$.get("hello.html",
function(content){ $("body#tinymce").text(content);});
return false;});
How can I do?
我能怎么做?
回答by Darin Dimitrov
You could try with the setContentfunction:
您可以尝试使用setContent函数:
$.get("hello.html", function(content) {
// if you have one tinyMCE box on the page:
tinyMCE.activeEditor.setContent(content);
});
or even shorter:
甚至更短:
$.get("hello.html", tinyMCE.activeEditor.setContent);
回答by Stefano Esposito
Using the jQuery version of tinyMCE with jQuery plugin you could use this
使用带有 jQuery 插件的 tinyMCE 的 jQuery 版本,您可以使用它
$.get("hello.html", function(content) {
$('#input-corpo').html(content);
});