Javascript 如何防止重复提交按钮

Javascript 如何防止重复提交按钮,javascript,html,ajax,Javascript,Html,Ajax,我有两个按钮,一个按钮用于增加计数,另一个按钮用于提交计数并移动到下一页。但我面临的错误是,当我按下“继续”按钮时,需要按下两次按钮才能进入下一页,而且计数会加倍并提交。代码如下: 代码: 确认 继续简单地说,在事件处理程序中(对于id=“finish”没有元素,缺少该处理程序),可以执行以下操作: $(函数(){ $(“#完成”)。单击(函数(){ //将此缓存以在另一个函数中使用。 $this=$(this); $this.prop(“禁用”,true); log(“发送AJAX调用…您不

我有两个按钮,一个按钮用于增加计数,另一个按钮用于提交计数并移动到下一页。但我面临的错误是,当我按下“继续”按钮时,需要按下两次按钮才能进入下一页,而且计数会加倍并提交。代码如下:

代码:

确认

继续简单地说,在事件处理程序中(对于
id=“finish”
没有元素,缺少该处理程序),可以执行以下操作:

$(函数(){
$(“#完成”)。单击(函数(){
//将此缓存以在另一个函数中使用。
$this=$(this);
$this.prop(“禁用”,true);
log(“发送AJAX调用…您不能再次提交完成按钮…请稍候…”);
setTimeout(函数(){
log(“从服务器获取输出…”);
$this.prop(“禁用”,false);
}, 1000);
});
});


Finish
您可以在单击操作后向按钮添加禁用属性,然后进行处理。我在这里没有看到任何
id=“Finish”
按钮,您是否忘记更新代码?@CapitanFindus我更新了代码单击后在按钮中添加禁用属性bcoz与其他进程发生冲突。你可以用一只手看console@xr00tme你能告诉我在哪里加吗
  <button class="btn_success" id="btn_add" value="add areas">Confirm</button>

  <button class="brown-button" id="Proceed" onclick="location.href='gallery.php'; return false;">Proceed &nbsp;In simple terms, in your event handler (which is missing, for 
id="finish"
there's no element), you can do something like this:

$(function () {
  $("#finish").click(function () {
    // Cache this to use inside another function.
    $this = $(this);
    $this.prop("disabled", true);
    console.log("Sending AJAX call... You can't re-submit the Finish button again... Please wait...");
    setTimeout(function () {
      console.log("Got output from server...");
      $this.prop("disabled", false);
    }, 1000);
  });
});