2011-03-10 68 views
2

我試圖添加自定義標記到在編輯器中選擇的內容,但<title>內容</title>不起作用。這工作雖然:[title]內容[/title]使用ed.selection.setContent添加自定義標記TinyMCE

谷歌搜索使我相信,我需要用這些線爲好,但它並不能幫助:

extended_valid_elements : "title", 
custom_elements: "title", 

例子:

出於某種原因,這個代碼不工作:

setup : function(ed) { 
    // Add a custom button 
    ed.addButton('mybutton', { 
    title : 'My button', 
    'class' : 'Mybutton', 
    image : 'img/example.gif', 
    onclick : function() { 
     // Add you own code to execute something on click 
     ed.focus(); 
     ed.selection.setContent("<title>" + ed.selection.getContent() + '</title>'); 

    } 

但這個工程:

setup : function(ed) { 
    // Add a custom button 
    ed.addButton('mybutton', { 
    title : 'My button', 
    'class' : 'Mybutton', 
    image : 'img/example.gif', 
    onclick : function() { 
     // Add you own code to execute something on click 
     ed.focus(); 
     ed.selection.setContent("[title]" + ed.selection.getContent() + '[/title]'); 

    } 

回答

3

這是去

extended_valid_elements : "title", 
custom_elements: "title", 

你看不到,因爲標題是不是比其他地方的頭什麼定義的方式。 你會發現你的標題標籤使用螢火蟲,它將持有你期望持有的(ed.selection.getContent()包裹到標題標籤中。):

+0

我正在使用「title」而不是我的特定標籤所以它可能會誤導你的答案。我們只是說標籤被稱爲「abc」---我在extended_valid_elements和custom_elements設置中有這個標籤。我仍然無法在我定義的textarea的標籤中創建該標籤。這個想法是,用戶在添加內容時會在textarea字段中看到一個描述性標籤。 TinyMCE有可能嗎? – Raj 2011-03-12 04:34:55

+0

我看到你在說什麼順便說一句關於Firebug以及標籤如何保留我期望的內容。這部分似乎工作。我只想讓相同的標籤顯示在用戶界面中,因爲這對用戶很有幫助。有沒有辦法做到這一點? – Raj 2011-03-12 06:17:45

+0

有一種方法,但它不是非常優秀的,你可以使用jQuery(或者獲取節點usign document.getelementBy ...)來獲取UI節點並在那裏添加一個html節點,你可以在那裏顯示消息,描述和任何東西你喜歡。當然,你需要關注UI的風格和外觀 – Thariama 2011-03-21 10:27:16

相關問題