如何启用和禁用Twitter Bootstrap Button? [英] How to enable and disable Twitter Bootstrap Button?
本文介绍了如何启用和禁用Twitter Bootstrap Button?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现在点击它时禁用按钮的方案,然后在ajax请求成功完成后再次启用它。
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.
以下是我的代码片段。
表格
<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);
}
});
}
});
它不起作用。在Chrome上检查我的控制台告诉我未捕获的语法错误:意外的令牌(
。感觉这是一个愚蠢的错误,我无法弄明白。我已经读过 prop
适用于jQuery 1.6.1及更高版本,我在1.8.3。
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);
}
});
}
});
试试这个
这篇关于如何启用和禁用Twitter Bootstrap Button?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文