具有tinyMCE的textarea的setContent

Mil*_*loš 16 javascript textarea tinymce

我有一些textareas,所有这些都是tinyMCE.

我想设置特定文本区域的内容,但我找不到如何.

我试过这个:

 tinyMCE.get('title').setContent(selected_article_title);
Run Code Online (Sandbox Code Playgroud)

这是我的textarea:

<textarea style="width: 95%;" name="Title"  id="title"></textarea>
Run Code Online (Sandbox Code Playgroud)

在这里我的tinyMCE初始化:

tinyMCE.init({
// General options
mode : "specific_textareas",
theme : "advanced",
width: "100%",
plugins : "pagebreak,paste,fullscreen,visualchars",

// Theme options
theme_advanced_buttons1 : "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword",
theme_advanced_buttons2 :"",
theme_advanced_buttons3 :"",
theme_advanced_buttons4 :"",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
valid_elements : "i,sub,sup",
invalid_elements : "p, script",
editor_deselector : "mceOthers"
});
Run Code Online (Sandbox Code Playgroud)

我不知道为什么这不起作用,我使用的是tinyMCE网站上的例子http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

Rya*_*eal 14

我想这会解决你的问题

它适用于TinyMCE v:4..

// 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); // here my_editor is the id of a specific editor

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

代码的链接是TinyMCE setContent


Mil*_*loš 13

我有解决方案(Thariama给了我一些元素)

要使用tinyMCE设置textarea的内容,我们必须在初始化tinyMCE之前填写textarea.此外,答复如下:

  1. 创建textarea:

    <textarea style="width: 95%;" name="Title"  id="title"></textarea>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 设置textarea的内容:

    $('#title').html(selected_article_title);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 初始化tinyMCE:

    tinyMCE.init({
    // General options
    mode : "specific_textareas",
    theme : "advanced",
    width: "100%",
    plugins : "pagebreak,paste,fullscreen,visualchars",
    
    // Theme options
    theme_advanced_buttons1 : "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword",
    theme_advanced_buttons2 :"",
    theme_advanced_buttons3 :"",
    theme_advanced_buttons4 :"",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    valid_elements : "i,sub,sup",
    invalid_elements : "p, script",
    editor_deselector : "mceOthers"
    });
    
    Run Code Online (Sandbox Code Playgroud)

它已经完成了!请享用.


Tom*_*Tom 12

对于tinymce版本4,

tinymce.get('title').setContent(selected_article_title);
Run Code Online (Sandbox Code Playgroud)

工作得很好 - 也是在初始化编辑器之后.