Html 引导程序的禁用类和禁用属性之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32778263/
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
Difference between disabled class of bootstrap and disabled attribute
提问by Dhiraj
Hi friends i am using disabled class as well as disabled attribute as follows however i dont know the basic difference between both and when we have to use class and when to use attribute please clear my doubt I am using button in my code and i want to disable it so what will be the best way either use class disabled or attribute disabled
嗨,朋友们,我正在使用禁用类和禁用属性,如下所示,但是我不知道两者之间的基本区别以及何时必须使用类以及何时使用属性请清除我的疑问我在我的代码中使用按钮,我想禁用它,那么使用禁用类或禁用属性的最佳方法是什么
<button class="btn btn-primary disabled" type=" button"/>
disabled="disabled"
回答by wero
If you look at the bootstrap definitions the disabled styles are always defined for the presence of the disabled class or the disabled attributed:
如果您查看引导程序定义,则始终为禁用类或禁用属性定义禁用样式:
.btn.disabled,
.btn[disabled],
fieldset[disabled] .btn {
cursor: not-allowed;
...
}
So for styling you only need either class or the attribute.
因此,对于样式,您只需要类或属性。
Previous versions also included pointer-events: none;
which disabled mouse clicks on the button. Here setting either the disabled class or attribute effectively disabled the button.
以前的版本还包括pointer-events: none;
禁用鼠标点击按钮的功能。这里设置禁用类或属性有效地禁用了按钮。
In the current version 3.3.5 the pointer-events: none;
was dropped from .btn
. Then if you only use the class, the button looks disabled but still can be clicked.
在当前版本 3.3.5 中pointer-events: none;
,从.btn
. 然后,如果您只使用该类,该按钮看起来已禁用,但仍然可以单击。
Therefore I would use the disabled attribute for buttons.
因此,我会为按钮使用 disabled 属性。