设置和获取 HTML 内容
本指南介绍在 RichTextEditor 中设置和获取 HTML 内容的常用方法。
1. 用 JavaScript 获取内容
<!-- Create a new DIV element with all of the content that we want inside the Editor -->
<div id="div_editor1"></div> //Initialize Richtexteditor for the matched element
var editor1 = new RichTextEditor("#div_editor1");
//Setting Content with Javascript
editor1.setHTMLCode("Use inline HTML or setHTMLCode to set the default content.");<!-- Retrieve the HTML from the editor by using the editor.getHTMLCode() method. -->
<button onclick="alert(editor1.getHTMLCode())">Show Html Code</button>2. 通过 HTML <form> POST 自动获取内容
当 RichTextEditor 用于替换 <form> 中的 <textarea> 元素时,提交表单时 RichTextEditor 会模拟原始 <textarea> 的行为。也就是说,编辑器的内容会与其他表单元素一起提交,并以原始 <textarea> 的 name 属性作为键名。
<!-- Create a new DIV element with all of the content that we want inside the Editor -->
<textarea id="inp_editor1"><p>Initial Document Content</p></textarea>//Initialize Richtexteditor for the matched element
var editor1 = new RichTextEditor("#inp_editor1");