how to find out second click on a button
i make a jquery function and called it by linking.
<a href="javascript:myfunc(ID)">&开发者_如何学编程lt;/a>
and i want to check in my function that button is second time click or first time
and i want to make different different event on first and second click()
You can use .toggle()
, like this:
$("#myButton").toggle(function() {
//click first time
}, function () {
//click second time
});
You can add as many as you want actually, it just cycles through them, If you need to bomb out after the second click, just .unbind()
by adding a $(this).unbind('click')
at the bottom of the last click function, like this:
$("#myButton").toggle(function() {
//click first time
}, function () {
//click second time
$(this).unbind('click'); //without this, it goes back to the first function
//on the next click
});
精彩评论