← すべてのドキュメント

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 属性をキーとして、ほかのフォーム要素と一緒にそのまま POST されます。

<!-- Create a new DIV element with all of the content that we want inside the Editor -->
<textarea id="inp_editor1">&lt;p&gt;Initial Document Content&lt;/p&gt;</textarea>
//Initialize Richtexteditor for the matched element
var editor1 = new RichTextEditor("#inp_editor1");