如何找出第二次点击按钮 [英] how to find out second click on a button
本文介绍了如何找出第二次点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个jquery函数,并通过链接对其进行了调用.
i make a jquery function and called it by linking.
<a href="javascript:myfunc(ID)"></a>
我想检查一下按钮是第二次单击还是第一次单击
and i want to check in my function that button is second time click or first time
我想在第一次和第二次click()上做出不同的事件
and i want to make different different event on first and second click()
推荐答案
您可以使用 .toggle()
,像这样:
You can use .toggle()
, like this:
$("#myButton").toggle(function() {
//click first time
}, function () {
//click second time
});
您可以根据需要实际添加任意数量,它会循环浏览它们.如果您需要在第二次单击后轰炸,只需 .unbind()
,方法是在最终点击功能的底部添加一个$(this).unbind('click')
,如下所示:
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
});
这篇关于如何找出第二次点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文