jQuery 如何禁用 Bootstrap 的按钮下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15697968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable Bootstrap's Button dropdown
提问by Mike
Link here: bootstrap button dropdowns
链接在这里:引导按钮下拉菜单
I'd like to disable this button dropdown, i added disabled
class to <a>
but the dropdown can still be opened by clicking the dropdown button. Any ideas?
我想禁用此按钮下拉菜单,我添加了disabled
类,<a>
但仍然可以通过单击下拉按钮打开下拉菜单。有任何想法吗?
回答by Christopher Marshall
Add disabled
class to the button...
将disabled
类添加到按钮...
<div class="btn-group">
<button class="btn btn-primary dropdown-toggle disabled" data-toggle="dropdown">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
That works when editing via bootstraps site. I did notice that they're not using the anchor like their example.
这在通过引导站点编辑时有效。我确实注意到他们没有像他们的例子那样使用锚点。
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
回答by Jai
Yeah you can do it this way:
是的,你可以这样做:
$('.dropdown-toggle').data('toggle', '');
This works only when it gets this property: data-toggle="dropdown"
, You can either change the dropdown
to ''
blank one.
这仅在获得此属性时才有效:data-toggle="dropdown"
,您可以将 更改dropdown
为''
空白。
Or you can try and remove the attr of data-toggle
或者你可以尝试删除 attr data-toggle
$('.dropdown-toggle').removeAttr('data-toggle');
回答by gawpertron
All you need to do is set the disabled property of the button.
您需要做的就是设置按钮的禁用属性。
$('.dropdown-toggle').prop('disabled', true);
http://getbootstrap.com/2.3.2/base-css.html#buttons Disabled state