如何从TinyMCE编辑器中提取HTML内容

Ike*_*kes 18 javascript tinymce

我是Javascript/TinyMCE的初学者,我试着理解如何从编辑器中获取HTML内容,并使用简单的alert()函数显示它.

我在HTML页面上有这个极简主义配置:

<div id="tiny">
<script type="text/javascript">
tinyMCE.init({
        // General options
        mode : "specific_textareas",
        editor_selector : "mceEditor"
});
</script>
</div>

<form method="post" action="somepage">
        <textarea id="myarea1" class="mceEditor">This will be an editor.</textarea>
</form>
Run Code Online (Sandbox Code Playgroud)

TinyMCE网站上,他们解释说我必须使用这个:

// Get the HTML contents of the currently active editor
console.debug(tinyMCE.activeEditor.getContent());
Run Code Online (Sandbox Code Playgroud)

这里

tinymce.activeEditor.getContent()
Run Code Online (Sandbox Code Playgroud)

我不知道为什么它不起作用

有人有想法吗?

yb0*_*007 27

我不知道为什么它不起作用

它不起作用,因为

console.debug(tinyMCE.activeEditor.getContent());

tinymce.activeEditor.getContent();
Run Code Online (Sandbox Code Playgroud)

这些陈述没有被执行.

尝试遵循这个FIDDLE ....

tinyMCE.init({
        // General options
        mode : "specific_textareas",
        editor_selector : "mceEditor"
});
Run Code Online (Sandbox Code Playgroud)

获取内容的功能....

function get_editor_content() {
  // Get the HTML contents of the currently active editor
  console.debug(tinyMCE.activeEditor.getContent());
  //method1 getting the content of the active editor
  alert(tinyMCE.activeEditor.getContent());
  //method2 getting the content by id of a particular textarea
  alert(tinyMCE.get('myarea1').getContent());
}
Run Code Online (Sandbox Code Playgroud)

点击按钮获取编辑器的内容...

<button onclick="get_editor_content()">Get content</button> 
Run Code Online (Sandbox Code Playgroud)