2010-05-10 47 views
1
var ButtonFarmAtivada = new Array(); 

function X() { 
var tableCol = dom.cn("td"); //cell 0 

//create start checkbox button 

ButtonFarmAtivada[index] = createInputButton("checkbox", index); 

ButtonFarmAtivada[index].name = "buttonFarmAtivada_"+index; 

ButtonFarmAtivada[index].checked = GM_getValue("farmAtivada_"+index, true); 

FM_log(3,"checkboxFarm "+(index)+" = "+GM_getValue("farmAtivada_"+index)); 

ButtonFarmAtivada[index].addEventListener("click", function() { 
     rp_farmAtivada(index); 
}, false); 

tableCol.appendChild(ButtonFarmAtivada[i]); 

tableRow.appendChild(tableCol); // add the cell 

} 

1)是否有可能創建一個數組中的按鈕,因爲我試圖在該示例中做?像一排按鈕?如何從另一個功能改變按鈕?

2)我問,因爲我將不得不從另一個函數來更改此按鈕,我想是這樣做的(不工作):

function rp_marcadesmarcaFarm(valor) { 

    var vListID = getAllVillageId().toString(); 

    FM_log(4,"MarcaDesmarcaFarm + vListID="+vListID); 

    var attackList = vListID.split(","); 

    for (i = 0; i <= attackList.length; i++) { 
     FM_log(3, "Marca/desmarca = "+i+" "+buttonFarmAtivada[i].Checked); 
     ButtonFarmAtivada[i].Checked = valor; 
    }; 
}; 

回答

0

對於1號)是,您可以。

function createInputButton(type, index) { // um, why the 'index' param? 
    // also, why is this function called 'createInputButton' 
    // if sometimes it returns a checkbox as opposed to a button? 
    var inputButton = document.createElement("input"); 
    inputButton.type = type; // alternately you could use setAttribute like so: 
          // inputButton.setAttribute("type", type); 
          // it would be more XHTML-ish, ♪ if that's what you're into ♫ 
    return inputButton; 
} 

我真的不明白第2部分,對不起。

+0

2)如何從另一個函數訪問該按鈕,例如,如果我想檢查用你的函數創建的按鈕是否被「檢查」(inputButton.Checked)? – FernandoSBS 2010-05-10 04:10:33

+0

我懷疑你的問題是區分大小寫的問題;嘗試將'ButtonFarmAtivada [i] .Checked'更改爲'ButtonFarmAtivada [i] .checked' – 2010-05-10 04:39:08

相關問題