如何在jquery表单插件中禁用点击提交按钮并重新启用响应


how to disable submit button on click and re-enable on the response in jquery forms plugin

我希望能够禁用jquery表单插件中的提交按钮,然后当检索到响应时,它应该变为启用。我正在尝试通过下面的代码,但一旦在onlick事件中我禁用了按钮,它就会以某种方式停止提交。尽管我可以更改按钮的类别。

我做错了什么?

代码如下:

function timing(){
 d=Math.round(new Date().getTime() / 1000);
 $('input[name=timedate]').val(d);
 var btn1 = $('#post_global');  
 btn1.val('posting');
 btn1.removeClass('t_s').addClass('t_sDisabled');
 btn1.prop('disabled',true);    
  }
 (function() {
 $('form').ajaxForm({
dataType: 'json', 
beforeSubmit: validate,
success: processResponse
}); 
  })();  
 function processResponse(data) {
  document.getElementById('upfile').value = "";
  document.getElementById('fileinfo').innerHTML = "";
  document.getElementById('txt1').value="post anything...";
   var status = $('#status');   
if(data.errors == ""){
    status.hide().html(data.htmlResponse).fadeIn(1000);
} else{
alert(data.errors);
    }
var btn2 = $('#post_global');   
btn2.val('post');
btn2.removeClass('t_sDisabled').addClass('t_s');    
btn2.prop('disabled',false);
  }

这就是我认为您正在寻找的答案。如果你想要更多,只需在下面评论你想要的:

$("#btn2").click(function() {
$('#btn2').attr("disabled", true);
//Do the request here
$('#btn2').attr("disabled", false);}

可能是这个?

function timing(){
 d=Math.round(new Date().getTime() / 1000);
 $('input[name=timedate]').val(d);
 var btn1 = $('#post_global');  
 btn1.val('posting');
 $('#btn2').attr("disabled", true);
  }
 (function() {
 $('form').ajaxForm({
dataType: 'json', 
beforeSubmit: validate,
success: processResponse
}); 
  })();  
 function processResponse(data) {
  document.getElementById('upfile').value = "";
  document.getElementById('fileinfo').innerHTML = "";
  document.getElementById('txt1').value="post anything...";
   var status = $('#status');   
if(data.errors == ""){
    status.hide().html(data.htmlResponse).fadeIn(1000);
} else{
alert(data.errors);
    }
var btn2 = $('#post_global');   
btn2.val('post');
$('#btn2').attr("disabled", false);
  }