我想知道是否和如何你可以傳遞一個jQuery命令,函數的參數jQuery的通帶參數的函數的參數jQuery的方法
var childs = ["#foo", "#bar"];
loopTheChilds("trigger('change')");
loopTheChilds("prop('disabled', true)");
var loopTheChilds = function (operation) {
$.each (childs, function (idx, val) {
$(val)[operation]();
});
}
我的GOL將獲得此
$("#foo").trigger("change");
$("#bar").trigger("change");
// or
$("#foo").prop('disabled', true);
$("#bar").prop('disabled', true);
或知道如何以任何其他方式獲得相同的結果。
感謝
這是可能的的eval(),但使用eval()被認爲是不好的做法。 – WaldemarIce