简体   繁体   English

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

[英]Change textbox text inside a tinymce editor using javascript

I have a textbox inside a tinymce editor. 我在tinymce编辑器中有一个文本框。 I want to change textbox text by using javascript. 我想使用javascript更改文本框文本。 Can any one tell me how is this possible? 谁能告诉我这怎么可能? Thank you 谢谢

Use tinymce setContent method I hope this will help you.. 使用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'});

please check the tinymce documentation http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent 请检查tinymce文档http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

This is not difficult. 这并不困难。 First, you will need to get the body of your editor. 首先,您将需要获得编辑器的主体。 Then you can try to find your textarea. 然后,您可以尝试找到您的文本区域。 As bios suggested it is helpfull to give an id to your textarea. 正如BIOS所建议的,为您的文本区域提供一个ID很有帮助。 Here is the necessary code 这是必要的代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM