防止使用jQuery单击第二个按钮 [英] Prevent second button click using jQuery

查看:92
本文介绍了防止使用jQuery单击第二个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个按钮.如果用户第二次单击该按钮,我不想执行任何操作.我有以下代码.但这是行不通的.有人可以帮忙吗?

I have a button on my page. I don't want to do any operation if the user clicks on the button for second time. I have the following code. But it is not working. Can someone help??

      $("#myButton").click(function(){
        var count = 0;
        count++;
        alert("button");
        if(count>1)
          $('#myButton').prop('disabled', true);
     });
     <button type="button" id="myButton" > Click Me </button>

这是 FIDDLE

推荐答案

您可以为此在jquery中使用一个

you can use one in jquery for that

$("#myButton").one("click",function(){

它将为该元素的事件附加一个处理程序,该事件最多执行一次.

It will attach a handler to an event for the element which will executed at most one.

这篇关于防止使用jQuery单击第二个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆