使用javascript更改tinymce编辑器中的文本框文本

时间:2012-11-14 07:09:06

标签: javascript jquery tinymce wysiwyg rte

我在tinymce编辑器中有一个文本框。我想通过使用javascript更改文本框文本。 谁能告诉我这怎么可能? 谢谢

2 个答案:

答案 0 :(得分:0)

使用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

答案 1 :(得分:0)

这并不困难。首先,您需要获得编辑的正文。然后你可以尝试找到你的textarea。正如bios所说,给你的textarea提供一个id是有帮助的。这是必要的代码

var editor = tinymce.get('your_editor_id');
$(editor.getBody()).find('textarea#your_textarea_id').innerHTML = 'my_new_text';