我有以下内容:
HB.formButtons.deactivatingButton = function(element) {
element.parent().removeClass(HB.formButtons.SUBMIT_BUTTON_STYLE);
}
并且每次我需要它时都会按照以下方式调用它:
HB.formButtons.deactivatingButton($(HB.personalDetails.SUBMIT_CHANGE_PASSWORD_SELECTOR));
HB.formButtons.deactivatingButton($(HB.personalDetails.CANCEL_CHANGE_PASSWORD_SELECTOR));
有没有办法调用一次(传递尽可能多的参数)并可能在HB.formButtons.deactivatingButton
中引入一个循环?
答案 0 :(得分:2)
这绝对可能如下:
HB.formButtons.deactivatingButton = function(elementsArray) {
if($.isArray(elementsArray))
{
$.each( elementsArray, function( index, element){
element.parent().removeClass(HB.formButtons.SUBMIT_BUTTON_STYLE);
});
}
}
只调用此函数一次,如下所示:
var elementsArray = [$(HB.personalDetails.SUBMIT_CHANGE_PASSWORD_SELECTOR),
$(HB.personalDetails.CANCEL_CHANGE_PASSWORD_SELECTOR)];
//call the function
HB.formButtons.deactivatingButton(elementsArray);