禁用多次单击按钮

时间:2016-04-28 17:46:30

标签: javascript jquery

我试图禁用多次点击按钮。代码如下

<div class="pull-right"> 
  <input type="button" name="Submit" class="btn btn-success" id="anext" value='<s:text name="generic.next.caps"></s:text>' onclick='showPopUp();'/>
</div>

<div class="pull-right">
  <s:submit type="submit" name="Submit" cssClass="btn btn-success" id="acontd" value="%{getText('generic.continue.caps')}" action="ActionName"/>
</div>

我的解决方案:

$("anext").click(function(){
    $("aptcnext").prop("disabled", true);
});
$("acontd").click(function(){
    $("aptccontd").prop("disabled", true);
});

但是,这不起作用。有人能帮帮我吗?

3 个答案:

答案 0 :(得分:1)

试试这个

&#13;
&#13;
$("input[type='submit']").click(function() {
  $(this).prop("disabled", true);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pull-right">
  <input type="submit" name="Submit" class="btn btn-success" id="anext" onclick='showPopUp();' />
</div>

<div class="pull-right">
  <input type="submit" name="Submit" class="btn btn-success" id="acontd" action="ActionName" />
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用one方法仅接受一次点击事件

$(function () {
  $("#anext").one('click', function(e){
    alert('ok');
  });
  $("#acontd").one('click', function(){
    alert('ok');
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="pull-right">
    <input type="submit" name="Submit" class="btn btn-success" id="anext" onclick='showPopUp();' />
</div>

<div class="pull-right">
    <input type="submit" name="Submit" cssClass="btn btn-success" id="acontd" action="ActionName" />
</div>

答案 2 :(得分:0)

 $('#disable').on('click', function(){
    $('#disable').attr("disabled", true);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="disable">Disable Me!</button>
<p>Hello</p>