dongyong8491 2013-02-11 06:22
浏览 60

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

i want to be able to make the submit button in jquery form plugin disabled and then when the response is retrieved, it should become enable. i am trying thru the code below but as soon as in the onlick event i disabled the button it somehow stops the submission. although i am able to change the class of the button.

what am i doing wrong?

code is like this:

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);
  }
  • 写回答

1条回答 默认 最新

  • dqq3623 2013-02-11 06:31
    关注

    This is the answer that I think you're looking for. If you want more, just comment what you want below:

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

    Possibly this?

    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);
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料