【问题标题】:How to change a button from another function?如何从另一个功能更改按钮?
【发布时间】:2010-05-10 02:33:39
【问题描述】:
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;
     };
};

【问题讨论】:

    标签: javascript arrays button


    【解决方案1】:

    对于数字 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 部分,抱歉。

    【讨论】:

    • 2) 如何从另一个函数访问该按钮,例如,如果我想检查使用您的函数创建的按钮是否已“选中”(inputButton.Checked)??
    • 我怀疑您的问题是区分大小写的问题;尝试将ButtonFarmAtivada[i].Checked 更改为ButtonFarmAtivada[i].checked
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多