18

いくつかのテキストエリアがあり、それらはすべて tinyMCE を使用しています。

特定のテキストエリアのコンテンツを設定したいのですが、方法がわかりません。

私はこれを試しました:

 tinyMCE.get('title').setContent(selected_article_title);

ここに私のテキストエリアがあります:

<textarea style="width: 95%;" name="Title"  id="title"></textarea>

そして、ここで私の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"
});

これが機能しない理由がわかりません。tinymce Web サイトhttp://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContentの例を使用しています。

4

9 に答える 9

13

私には解決策があります(いくつかの要素を提供してくれたタリアマに感謝します)

tinyMCE を使用してテキストエリアのコンテンツを設定するには、tinyMCE を初期化する前にテキストエリアに入力する必要があります。また、回答は以下のとおりです。

  1. テキストエリアを作成します。

    <textarea style="width: 95%;" name="Title"  id="title"></textarea>
    
  2. テキストエリアのコンテンツを設定します。

    $('#title').html(selected_article_title);
    
  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"
    });
    

そして、それは完了です!楽しみ。

于 2012-08-03T06:36:52.523 に答える
12

tinymce バージョン 4 の場合、

tinymce.get('title').setContent(selected_article_title);

エディターを初期化した後でも問題なく動作します。

于 2015-07-22T20:35:15.147 に答える
3

これを使って

tinyMCE.get('title').setContent(selected_article_title);

動作しません。エディターのコンテンツを設定します。

エディターのソース html 要素 (テキストエリア) を設定するには、次を使用して直接設定する必要があります。

$('#title').html(selected_article_title);

エディタはテキストエリアと同じではないことに注意する必要があります!

于 2012-08-02T15:58:28.913 に答える
0

msoタグを含むコンテンツ(たとえば、番号付きリストを含む、outlook2013 から生成された HTML コンテンツ) を設定すると、リスト要素が失われます。tinymce.activeEditor.setContent(foo)で設定するか、最初に textarea コンテンツを設定してから tinymce を初期化すると、同じ結果が得られます。リスト要素が正しく表示されず、左揃えになります。しかし、 we を使用して設定するとsetContent(foo, { format:'raw' })、リスト要素が適切に表示されます。なんで?

于 2015-09-01T08:19:57.803 に答える
0

以下は tinymce バージョン 4 で動作し、ドラッグ中にエディターをテキストエリアとして表示しません。

function initializeEditors() {
    var editorContent = {};
    $("#photo-list").sortable({
        start: function (e, ui) {
            $('.attachment-info').each(function () {
                var id = $(this).attr('id');
                editorContent[id] = tinyMCE.get(id).getContent();
            });
        },
        stop: function (e, ui) {
            $('.attachment-info').each(function () {
                var id = $(this).attr('id');
                tinymce.execCommand('mceRemoveEditor', false, id);
                tinymce.execCommand('mceAddEditor', true, id);
                tinyMCE.get(id).setContent(editorContent[id]);
            });
        }
    });
}
于 2016-10-19T16:50:40.390 に答える