![](/img/trans.png)
[英]How can I use a callback function as a parameter, in which has its own independent parameters?
[英]How to add more function to the checkbox which has its own current function with Javascript
復選框的當前功能:
<input type="checkbox" onfocus="EnsureSelectionHandlerOnFocus(event,this,12)" onclick="ToggleAllItems(event,this,12)" title="Select or deselect all items" id="cbSelectAll" class="s4-selectAllCbx">
我如何向復選框的onclick添加更多功能,例如: onclick="ToggleAllItems(event,this,12)"
vs onclick="select_remainingitems();"
由於復選框當前功能的復雜性,我希望看到單擊該復選框時,該復選框可以同時運行這兩個功能。
您可以這樣操作:
onclick="select_remainingitems();function_two();function_tree();"
如果您想知道是否可以同時運行兩個不同的JS函數:不能,因為Javascript是單線程的。
編輯
我建議這個
<input type="checkbox" onfocus="EnsureSelectionHandlerOnFocus(event,this,12)" onclick="multiple_functions();" title="Select or deselect all items" id="cbSelectAll" class="s4-selectAllCbx">
function multiple_functions(){
first_function();
second_function();
}
function first_function(){
alert("Im the first function");
}
function second_function(){
alert("Im the second function");
}
希望這可以幫助
你可以試試看
HTML
<input type="checkbox" id="ddfd" /> click me
JS
$('body').on('click','#ddfd','',function(){
function1();
function2();
function3();
});
function function1(){
alert("function 1");
}
function function2(){
alert("function 2");
}
function function3(){
alert("function 3");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.