2017-09-16 63 views
0

我有一個表單有多個<input>字段。我想運行一個JavaScript函數,當每個人都「參與」,所以jQuery的.focus()似乎是做到這一點的方式。jQuery .focus()不會觸發每個表單元素

運行...

$('input').focus(change_submit_button_state(form_id, form_elements_id_array)); 

只運行change_submit_button_state功能雖然一次。

這裏怎麼回事?

回答

0

,如果你想傳遞參數

$('input').focus(function() { 
    change_submit_button_state(form_id, form_elements_id_array); 
}); 

,否則你會需要一個匿名函數,如果你不需要爭論

$('input').focus(change_submit_button_state); 

當函數之後添加括號,你打電話它並返回結果,所以你在做什麼更像

var x = change_submit_button_state(form_id, form_elements_id_array); 
//  ^probably returns "undefined", unless you've specified someting else 

$('input').focus(x); // still undefined 
相關問題