[英]Check box checked property doesn't change in Chrome or Firefox Developer Tools
Suppose you have a check box, which is checked. 假设您有一个复选框,该复选框已选中。 In Chrome or Firefox, when you click inspect element, in the HTML you will see:
在Chrome或Firefox中,单击inspect元素时,在HTML中您会看到:
<input checked="checked" class="some-class" id="some-id" name="some-name" type="checkbox" value="some-value">
I expect, that when I click on the check box and uncheck it, the html will change and the checked
property will disappear: 我希望,当我单击复选框并取消选中它时,html将更改,并且
checked
属性将消失:
<input class="some-class" id="some-id" name="some-name" type="checkbox" value="some-value">
However, that's not the case. 但事实并非如此。 Why?
为什么?
That is just the default property defined by the HTML attribute
of the element when loaded. 这只是加载时元素的HTML
attribute
定义的默认属性。 When unchecked, its the DOM property
that is whats actually toggled. 取消选中时,它的
DOM property
实际上是切换的。 Which is why the attribute does not seem to change. 这就是属性似乎没有改变的原因。
This follow code outputs the current DOM checked
property to the console: 此跟随代码将当前DOM
checked
属性输出到控制台:
$("input").click(function(){
console.log($(this)[0].checked);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.