我有一个非常简单的代码不起作用,我不明白我错过了什么。
外部资源
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
HTML
<p>
<button id="btn-id" class="btn btn-large btn-primary" type="button" data-loading-text="loading stuff...">Click Me</button>
</p>
JavaScript
$(document).ready(function () {
$("#btn-id").button();
$("#btn-id").click(function () {
//$("#btn-id").attr("disabled",true);
$(this).button('loading');
setTimeout(function () {
//this desn't work. The button resets but it doesn't get disabled afterwards
$("#btn-id").button('reset').attr("disabled", true);
//the bellow line works as expected
//$("#btn-id").button('reset').addClass("btn-success");
}, 2000);
});
});
似乎在之后button('reset')
,我可以addClass('someclass')
但我不能再禁用该按钮了。
为什么这不起作用,我该如何解决?