简体   繁体   English

如何在按钮onclick后禁用按钮

[英]How to disable button after button onclick

I have a button using onclick return confirm ... I wish when the confirm submitted... the second time to click the button it will pop up alert message to inform the user button only can click once time. 我有一个使用onclick返回确认的按钮...希望在提交确认时...第二次单击该按钮时,它将弹出警报消息,通知用户该按钮只能单击一次。

SO far , I have already try the one function but not working. 到目前为止,我已经尝试了一种功能,但是没有起作用。

$("#once").one("click", function() {
  alert('this only happens once');
});

The following code is my button 以下代码是我的按钮

<input type="submit" id="once" class="button" style="width:100px;" onclick="return  
confirm('Are you sure you want <?php  echo $show_venue['venue'];?>  be your party venue 
 ?');"  value="CHOOSE" name="choose_venue">

You're not disabling the button after the click. 单击后,您不会禁用按钮。

$(this).prop('disabled', true);

Here's a fiddle with the code you are after: http://jsfiddle.net/UT79m/6/ 这是您正在寻找的代码的摆弄: http : //jsfiddle.net/UT79m/6/

You could add a class to set a 'selected' state after the first click: 您可以在第一次单击后添加一个类以设置“选定”状态:

$("#once").on("click", function() {
   if($(this).hasClass('selected'))
       return;
   alert('this only happens once');
   $(this).addClass('selected');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM