如何从其他功能更改按钮?

时间:2010-05-10 02:33:39

标签: javascript arrays button

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;
     };
};

1 个答案:

答案 0 :(得分: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部分,抱歉。