2012-12-30 46 views
2

我在wordpress中遇到了tinymce問題。我需要放入tinymce元素。在tinymce編輯器中,有兩個選項卡「Visual」和「HTML」。當我在「HTML」中使用我的代碼時,它的作品。但是,當我想在 「視覺」 它不工作使用...Wordpress tinymce插入文本

我試圖像這樣:

的JavaScript

function insert_tag(text){ 
    var cont = document.getElementById('bbp_topic_content'); 
    cont.value += '<div>' + text + '</div>'; 
} 

HTML

<a onclick="insert_tag('HELLO')" >Insert text</a> 

請幫忙嗎?

+0

你應該爲'tinyMCE'創建一個插件來完成這類工作。檢查[這個答案](http://stackoverflow.com/questions/14/adding-button-to-trigger-html-code-fragment-into-tinymce-editor-via-jquery/14012747#14012747)得到一個想法。 –

+0

哪裏沒有簡單的方法? :) – andys

+0

有人?任何幫助? – andys

回答

6

你可以試試這個

function insert_tag(text){ 
    if(tinyMCE && tinyMCE.activeEditor) 
    { 
     tinyMCE.activeEditor.selection.setContent('<div>' + text + '</div>'); 
    } 
    return false; 
} 

a標籤

<a onclick="return insert_tag('HELLO')" >Insert text</a> 

Reference還可以使用return

+0

非常感謝你我會嘗試 – andys

+0

@ user1139767,不客氣:-) –

+1

它工作;)非常感謝你。我知道這可以更容易。 – andys