2012-11-07 28 views
0

我正在使用CKeditor,此代碼僅適用於按鈕。我在Dom中存儲xml。我想在選擇框的其他功能中使用xml。選擇框的代碼與此按鈕代碼類似。當我在選擇框中打出列表時,我想看到<chr></chr>之間的單詞。我不想將<chr>置於選項中。在其他函數中使用var在CKeditor中進行選擇

type: 'button', 
id: 'btnFind', 
align: 'left', 
style: 'width:100%', 
label: 'add', 
onClick: function() { 
    var y = this.getDialog(); 
    var value1 = y.getValueOf('replace', 'chgWord'); 
    var value2 = y.getValueOf('replace', 'title'); 
    var xml = "<channel><title>" + value1 + "</title><chr>" + value2 + "</chr></channel>", 
    xmlDoc = $.parseXML(xml), 
    $xml = $(xmlDoc), 
    $title = $xml.find("title"); 
    $("#cke_119_select").append("<option value='" + $title.text() + "'>" + $title.text() + "</option>"); 
    $title = $xml.find("chr"); 

這是selecbox代碼:

type: 'hbox', 
widths: ['200px', '90px'], 
children: [{ 
    type: 'select', 
    label: '약어 LIST :', 
    size: 5, 
    style: 'width:100%', 
    labelLayout: 'horizontal', 
    id: 'list', 
    items: [], 
    onClick: function() { 

     selValue = $("#cke_119_select option:selected").val(); 
     selText = $("#cke_119_select option:selected").text(); 
     selIndex = $("#cke_119_select option").index($("#cke_119_select option:selected")); 
     selBox = $("#cke_119_select"); 
     selOption = selBox.attr("options"); 

     var y = this.getDialog(); 
     var value1 = y.setValueOf('replace', 'chgWord'); 
     value1.setValue(selValue); 
+1

你的問題是變量?請具體說明,因爲代碼本身沒什麼意義 – charlietfl

+0

我想在另一個函數中使用「var」。由於parseXML的代碼只能在按鈕的函數中使用,所以我不能在select的另一個函數中使用「var xml」int。 – Albright

回答

1

var是JavaScript的關鍵字,並且獨立於正在使用它,當你願意,你可以使用它。

如果你在一個函數是那麼「變種」將創建一個局部變量,「沒有變種」將查找範圍鏈,直到它找到的變量或打全球範圍內(此時它會創建它)。 https://stackoverflow.com/a/1470494/694325

你已經甚至有兩個的onclick功能var,所以你的確可以,做已經在使用它。

var xml = "<channel><title>" + value1 + "</title><chr>" + value2 + "</chr></channel>", 
    xmlDoc = $.parseXML(xml), 
    $xml = $(xmlDoc), 
    $title = $xml.find("title"); 

,對於例如創建與此同時四個變量,像var a=1,b=2,c=3;

var y = this.getDialog(); 

這正是聲明變量的方法相同。您的問題不在var這裏。

它看起來像你想設置一個richCombo的值/值。 Maby你可以在onClick裏面嘗試像var theValue = this.getValue();this.setValue("New Value");這樣的功能。另外,onClick: function (value) { ... alert(value); ...}可能會有用。如果您想更改物品,請嘗試在onClick中訪問this._.items。如果不知道更多關於您正在嘗試的內容,我無法幫助您,對不起!

+0

非常感謝yuo。這對我很有幫助。我用localStorage來做到這一點。你的回答給了我更多的信息! – Albright

+0

我很高興我可以幫助你! – Nenotlep

1

如果要聲明var以外的第一個功能,您可以使用在第二

var xml; 

function one(){ 
    xml= "<channel><title>" + value1 + "</title><chr>" + value2 + "</chr></channel>"; 

} 

function two(){ 
    /* can access xml here that was set in function one*/ 
} 
相關問題