18

私は 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>

TinyMCE ウェブサイトで、彼らは私がこれを使用しなければならないと説明しました:

// Get the HTML contents of the currently active editor
console.debug(tinyMCE.activeEditor.getContent());

そしてここに

tinymce.activeEditor.getContent()

なぜうまくいかないのかわからない

誰かがアイデアを持っていますか?

4

4 に答える 4

33

なぜうまくいかないのかわからない

機能していません

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

tinymce.activeEditor.getContent();

これらのステートメントは実行されていません。

このフィドルに従ってみてください....

tinyMCE.init({
        // General options
        mode : "specific_textareas",
        editor_selector : "mceEditor"
});

コンテンツを取得する関数 ....

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());
}

ボタンのクリックでエディターのコンテンツを取得...

<button onclick="get_editor_content()">Get content</button> 
于 2012-12-24T16:56:18.317 に答える
2

たぶんそうですか?変数は ですがtinyMCE、 を呼び出しgetContent()ていtinymceます。JS では大文字と小文字が区別されます ;)

于 2012-12-24T15:57:11.877 に答える
1

私は解決策を探していて、上記のいくつかを試した後、tinymce のドキュメントをさらに調べたところ、これが効果的であることがわかりました。
tiny mce 4の使い方

function getHTML()
{
   tinymce.activeEditor.on('GetContent', function(e) {
     console.log(e.content);
   });
}

その関数を onclick で呼び出して、結果を確認するだけです...
私のソースは次のとおりです: http://www.tinymce.com/wiki.php/api4:class.tinymce.ContentEvent

于 2014-08-23T18:43:40.470 に答える