使用JavaScript更改TinyMCE编辑器内的文本框文本

3

我在tinymce编辑器中有一个文本框。我想使用JavaScript更改文本框的文本。 有人能告诉我如何实现吗? 谢谢


你解决了吗?我之前也遇到了同样的问题,但是现在已经解决了!也许我可以分享我的解决方法,看看是否符合你的需求。 - chonnychu
2个回答

0
这并不难。首先,您需要获取编辑器的主体。然后,您可以尝试查找文本区域。正如bios建议的那样,为您的文本区域提供一个ID会很有帮助。以下是必要的代码。
var editor = tinymce.get('your_editor_id');
$(editor.getBody()).find('textarea#your_textarea_id').innerHTML = 'my_new_text';

-1
使用tinymce的setContent方法,希望这能帮到你。
// Sets the HTML contents of the activeEditor editor
tinyMCE.activeEditor.setContent('<span>some</span> html');

// Sets the raw contents of the activeEditor editor
tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'});

// Sets the content of a specific editor (my_editor in this example)
tinyMCE.get('my_editor').setContent(data);

// Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added
tinyMCE.activeEditor.setContent('[b]some[/b] html', {format : 'bbcode'});

请查看TinyMCE文档http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

这段代码设置了tinymce编辑器的内容。但实际上我想改变tinymce编辑器内部文本框的文本。我已经谷歌搜索了很多,但没有用。请帮帮我。 - user1809274
@user1809274 使用文本框ID设置文本,请查看此fiddle http://jsfiddle.net/3sSVa/,这将在文本框内设置文本,希望这能帮到您。 - super

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接