本文介绍了重置后,jQuery attr()在Bootstrap按钮上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的代码,无法正常工作,而且我不明白自己所缺少的内容.
I have a very simple code that doesn't work and I don't understand what I'm missing.
<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')
,但是我不能再禁用该按钮.
It seems that after button('reset')
, I can addClass('someclass')
but I can't disable the button anymore.
为什么这不起作用,我该如何解决?
Why is this not working and how can I fix it?
推荐答案
不确定这是否正确,但是您可以使用解决方法
Not sure if this is the right way, but you can use a workaround
$(document).ready(function () {
$("#btn-id").button();
$("#btn-id").click(function () {
$(this).button('loading');
setTimeout(function () {
$("#btn-id").addClass('btn-success').data('loading-text', 'OK').button('loading')
}, 2000);
});
});
这篇关于重置后,jQuery attr()在Bootstrap按钮上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!