考虑这段代码
<fieldset id="fieldset">
<input id="first" />
<div id="second" />
</fieldset>
和
$('#fieldset').attr('disabled', 'disabled')
console.log($('#first').is(':disabled'))
console.log($('#second').is(':disabled'))
输出是
true
false
我注意到输入标签遵循父属性,而且我认为所有具有小部件的标签都遵循但其他标签,如 div、a、span 或 .. 则没有。
为什么?
如果我想让 div 元素跟随父元素的属性,我应该怎么做?
最佳答案
A form control is disabled if its disabled attribute is set, or if it is a descendant of a fieldset element whose disabled attribute is set and is not a descendant of that fieldset element's first legend element child, if any.
div 没有被禁用,因为它不是表单控件。它不能被禁用,因为这样做是没有意义的。
关于javascript - 为什么DIV不遵循父级的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547852/