问题
Is there any possibilities to use the onclick
HTML attribute to call
more than one jQuery functions
onclick="$('#editParentDetailsViews').removeClass('tab selected');$('#editStudentDetailsPopupPnl').hide(); return false;"
Here, the first function work properly and the 2nd function not working.
回答1:
I suggest you these ways:
1-addEventListener
:
document.getElementById('btn').addEventListener('click', function(){
function1();
function2();
});
2-inline (onclick
)
onClick="function1();function2();"
3-Jquery Standard click function:
$("button").click(function(){
//Your functions code here
});
4-Jquery on:
$('#button').on('click',function(){
//Your code here
})
You can find more ways...
回答2:
Why dont you use jquery click() listener? Do not mix dom with jquery. Keep it simple.
$(yourselector).click(function(){
//call some funtions
});
回答3:
<div id="yup">click me</div>
js
$(function(){ // same as $(document).ready()...
$('#yup').on('click',function(){
// call function 1
// call function 2
// call function 3
// ...
});
});
DEMO
来源:https://stackoverflow.com/questions/26943872/multiple-function-call-on-html-onclick