twitter-bootstrap 禁用时删除数据切换属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24611727/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 21:04:40  来源:igfitidea点击:

Remove data-toggle attribute when disabled

javascriptjqueryhtmltwitter-bootstrapbootstrap-tabs

提问by peterbf

I have a list of tabs with elements that can be disabled - i.e. non-clickable. And when 'disabled' is added as a class, then the mouse over on the element is indicating that the tab is non-clickable. Unfortunately the element is clickable. I am trying to remove the datatoggle="tab"from the element when the element is disabled, but my jQuery skills aren't sufficient.

我有一个选项卡列表,其中包含可以禁用的元素 - 即不可点击。当“禁用”作为一个类添加时,鼠标悬停在元素上表示该选项卡不可点击。不幸的是,该元素是可点击的。datatoggle="tab"当元素被禁用时,我试图从元素中删除,但我的 jQuery 技能还不够。

I have a ul of class="nav nav-tabs" with id="myTabs"And I'm trying to remove the data-toggle attribute with this jQuery statement:

我有一个 ulclass="nav nav-tabs" with id="myTabs"并且我正在尝试使用此 jQuery 语句删除 data-toggle 属性:

$('#myTabs a').is('.disabled').removeAttr('data-toggle');

Bootply example

Bootply 示例

回答by Mohit Kumar

You can try this:-

你可以试试这个:-

$('#tabs li.disabled').find('a').removeAttr('data-toggle');

or

或者

$('#tabs li.disabled a').removeAttr('data-toggle');

Demo

演示

回答by rob

$('#myTabs a').is('.disabled') returns a boolean: false - you cannot call removeAttr on this!

$('#myTabs a').is('.disabled') 返回布尔值:false - 您不能对此调用 removeAttr!

Second your disabled class is on your li, not your .

其次,您的残疾人课程在您的 li 上,而不是您的 .

Try this:

试试这个:

$('#myTabs li.disabled a').removeAttr('data-toggle');