2012-08-02 15 views
8

के साथ टेक्स्टटेरा का सेटक मेरे पास कुछ textareas हैं और उनमें से सभी tinyMCE के साथ हैं।सेट tinyMCE

मैं विशिष्ट टेक्स्टरेरा की सामग्री सेट करना चाहता हूं, लेकिन मुझे यह नहीं मिल रहा है।

मैं इस tryed है:

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

और यहाँ मेरी tinyMCE init:

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.get('title').setContent(selected_article_title); 
यहाँ

मेरे पाठ क्षेत्र है काम कर रहा हूं, मैं tinyMCE वेबसाइट से उदाहरण का उपयोग कर रहा हूं http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

उत्तर

10

मैं (Thariama को thans जो मुझे कुछ तत्वों देता है) समाधान

tinyMCE का उपयोग कर एक पाठ क्षेत्र की सामग्री को सेट करने के लिए है, हम tinyMCE init से पहले पाठ क्षेत्र में भरने के heve। इसके अलावा, प्रतिक्रिया इस प्रकार है:

<textarea style="width: 95%;" name="Title" id="title"></textarea> 
  • पाठ क्षेत्र की सामग्री को सेट करें::

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

    1. पाठ क्षेत्र बनाएं

    और यह हो गया है! का आनंद लें।

  • 1

    का उपयोग करते हुए इस

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

    काम नहीं करेगा। यह आपकी संपादक सामग्री सेट करेगा।

    सीधे

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

    आप देखेंगे कि आपके संपादक पाठ क्षेत्र के रूप में है कि एक ही नहीं है पता होना चाहिए का उपयोग कर संपादक स्रोत HTML तत्व (पाठ क्षेत्र) आप इसे सेट करने की आवश्यकता होगी सेट करने के लिए!

    +0

    धन्यवाद @ थारीमा, लेकिन यह मेरे लिए काम नहीं कर रहा है। मेरा textarea अभी भी खाली है। –

    6

    TinyMCE संस्करण 4 के लिए,

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

    काम करता है ठीक - भी संपादक को प्रारंभ करने के बाद।

    +0

    यह मेरे लिए काम किया –

    0

    यदि आप ऐसी सामग्री सेट करते हैं जिसमें mso टैग हैं, (Outlook33 से उत्पन्न एक HTML सामग्री, जिसमें उदाहरण के लिए क्रमांकित सूची है), तो आप सूची तत्वों को खो देते हैं। के माध्यम से सेट करना tinymce.activeEditor.setContent (foo) या पहली बार टेक्स्टरेरा सामग्री सेट करना और फिर tinymce प्रारंभ करना एक ही परिणाम देता है, हम सूची तत्वों को ठीक से नहीं देख सकते हैं, वे गठबंधन छोड़ दिए गए हैं। लेकिन अगर हम setContent(foo, { format:'raw' }) का उपयोग करते हैं तो हम सूची तत्वों को सही तरीके से देखते हैं। क्यूं कर?

    6

    मुझे लगता है कि यह आपकी समस्या

    यह TinyMCE वी के लिए ठीक काम करता है का समाधान होगा: 4।

    // Sets the HTML contents of the activeEditor editor 
    tinyMCE.activeEditor.setContent('<span>some</span> html'); 
    
    // Sets the raw contents of the activeEditor editor 
    tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'}); 
    
    // Sets the content of a specific editor (my_editor in this example) 
    tinyMCE.get('my_editor').setContent(data); 
    
    // Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added 
    tinyMCE.activeEditor.setContent('[b]some[/b] html', {format : 'bbcode'}); 
    

    कोड के लिए लिंक TinyMCE setContent

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

    सुनिश्चित करें कि चयनित_article_title में कोई HTML टैग नहीं है।