开发者

how to find out second click on a button

开发者 https://www.devze.com 2023-01-07 17:07 出处:网络
i make a jquery function and called it by linking. <a href=\"javascript:myfunc(ID)\">&开发者_如何学编程lt;/a>

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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消