2011-10-04 21 views
0

我正在使用雅虎的YUI2富文本編輯器來替換標準文本區域。沒有RTE添加文本區域字段將字段內容正確地返回到我的PHP代碼。但是,當我使用RTE代碼時,jQuery「吸取」了var,並且在提交時不會將其返回到文本區域。因此var(sectiontext1)返回空。下面是文本區域的JS:YUI2富文本編輯器,無var返回到PHP

var myEditor1 = new YAHOO.widget.Editor('sectiontext1', { 
height: '100px', 
    width: '870px', 
    dompath: false, 
    animate: true, 
    toolbar: { 
     titlebar: 'Section Text 1', 
     buttons: [ 
      { group: 'textstyle', label: '', 
       buttons: [ 
        { type: 'push', label: 'Bold', value: 'bold' }, 
        { type: 'push', label: 'Italic', value: 'italic' }, 
        { type: 'push', label: 'Underline', value: 'underline' }, 
        { type: 'separator' }, 
        { type: 'color', label: 'Font Color', value: 'forecolor', disabled: true }, 
        { type: 'separator' }, 
        { type: 'push', label: 'Create an Unordered List', value: 'insertunorderedlist' }, 
        { type: 'push', label: 'Create an Ordered List', value: 'insertorderedlist' },         
        { type: 'separator' }, 
        { type: 'push', label: 'Indent', value: 'indent', disabled: true }, 
        { type: 'push', label: 'Outdent', value: 'outdent', disabled: true }, 
        { type: 'separator' },     
        { type: 'push', label: 'HTML Link CTRL + SHIFT + L', value: 'createlink', disabled: true }, 
        { type: 'separator' }, 
        { type: 'push', label: 'Remove Formatting', value: 'removeformat', disabled: true } 
       ] 
      } 
     ] 
    } 
}); 
myEditor1.render(); 

我以爲以上後,我可以只添加這和它的工作,但它並不:

$('#submit').click(function() { 
    myEditor1.saveHTML(); 
}); 

如何讓代碼返回變種,所以我可以在PHP中使用它?

謝謝!

回答

1

你是什麼意思不起作用? 您可能希望將結果實際存儲在變量中,並查看是否獲得了html 如果您確實在該var中包含該html,則可以隨意使用它,包括通過ajax請求將其發送到php。

var html = myEditor1.saveHTML(); 
alert('editor html: ' + html); 
+0

我的意思是,如果我不使用富文本編輯器,我會將變量的內容返回到PHP中。如果我使用rte,它會以某種方式「保留」var,並且不會返回瀏覽器,因此var顯示爲空。我會嘗試你在這裏列出的,看看會發生什麼。 –

+0

沒有工作。其中的一些東西包含變量。我要去看看其他的使用方法,比如使用TinyMCE –

+0

哦,不,請不要放棄。 YUI RTE比TinyMCE好得多​​。我已經使用了好幾年了,修改了它,添加了新的按鈕,並且它始終都能正常工作。 –