简体   繁体   中英

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:

<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:

<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. When unchecked, its the DOM property that is whats actually toggled. Which is why the attribute does not seem to change.

This follow code outputs the current DOM checked property to the console:

$("input").click(function(){
    console.log($(this)[0].checked);
});

Here is the JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM