如何与QUOT;启用"和"禁用" Twitter的引导按钮? [英] How to "enable" and "disable" Twitter's Bootstrap button?

查看:130
本文介绍了如何与QUOT;启用"和"禁用" Twitter的引导按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现上禁用单击它,然后再次启用Ajax请求成功完成后,一键场景。

以下是我的code的片段。

表格

 <按钮ID =btnSubmit按钮类型=提交级=BTN BTN-警告BTN-LG>!提交< /按钮>

的JavaScript

  $('#resForm')。验证({
  //禁用提交按钮
  $('#btnSubmit按钮')丙(禁用,真正的);  submitHandler:功能(形式){
    $阿贾克斯({
      .....典型AJAX的东西.....
      成功:功能(数据){
        警报(数据);
        $('成功')HTML(数据);
        //再次启用备用按钮
        $('#btnSubmit按钮')丙(禁用,假);
      },
      错误:功能(jqXHR,textStatus,errorThrown){
        //执行console.log(jqXHR);
      }
    });
  }
});

这是行不通的。并检查我在Chrome的控制台告诉我,未捕获的SyntaxError:。意外标记(这感觉就像是一个愚蠢的错误的地方,我无法弄清楚我已阅读道具是为jQuery的1.6.1,后来,我在1.8.3。


解决方案

  $('#resForm')。验证({
  submitHandler:功能(形式){
//禁用提交按钮
  $('#btnSubmit按钮')丙(禁用,真正的);
    $阿贾克斯({
      .....典型AJAX的东西.....
      成功:功能(数据){
        警报(数据);
        $('成功')HTML(数据);
        //再次启用备用按钮
        $('#btnSubmit按钮')丙(禁用,假);
      },
      错误:功能(jqXHR,textStatus,errorThrown){
        //执行console.log(jqXHR);
      }
    });
  }
});

试试这个

I am trying to achieve the scenario of disabling a button on clicking it, and then enabling it again after the ajax request has completed successfully.

The below is the snippet of my code.

Form

<button id="btnSubmit" type="submit" class="btn btn-warning btn-lg">Submit!</button>

Javascript

$('#resForm').validate({
  // disable submit button
  $('#btnSubmit').prop('disabled', true);

  submitHandler: function(form) {
    $.ajax({
      ..... typical ajax stuff .....
      success: function(data) {
        alert(data);
        $('success').html(data);
        // enable reserve button again
        $('#btnSubmit').prop('disabled', false);
      },
      error: function (jqXHR, textStatus, errorThrown) {
        // console.log(jqXHR);
      }
    });
  }
});

It doesn't work. And checking my console on Chrome tells me Uncaught SyntaxError: Unexpected token (. It feels like it's a stupid mistake somewhere and I can't figure it out. I have read that prop is meant for jQuery 1.6.1 and later and I am on 1.8.3.

解决方案

$('#resForm').validate({


  submitHandler: function(form) {
// disable submit button
  $('#btnSubmit').prop('disabled', true);
    $.ajax({
      ..... typical ajax stuff .....
      success: function(data) {
        alert(data);
        $('success').html(data);
        // enable reserve button again
        $('#btnSubmit').prop('disabled', false);
      },
      error: function (jqXHR, textStatus, errorThrown) {
        // console.log(jqXHR);
      }
    });
  }
});

Try this

这篇关于如何与QUOT;启用&QUOT;和&QUOT;禁用&QUOT; Twitter的引导按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆