在 Chrome DevTools 中,如何知道复选框或单选按钮是否被选中。当您单击以上任何一项时,该属性checked
根本没有显示。这很烦人,因为我必须猜测发生了什么,这会让开发过程变慢。我需要应用一些设置吗?
复选框有两个属性来说明它被选中:一个是 HTML/DOM 属性,一个是脚本对象的属性。 (dom 输入检查 https://html.spec.whatwg.org/multipage/input.html#dom-input-checked and attr 输入检查 https://html.spec.whatwg.org/multipage/input.html#attr-input-checked分别在规范中)。
规范有时使用这个词reflect https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflect表明这两种属性保持同步,但在本例中并非如此:DOM 属性是默认的选中状态,IDL 属性是当前的选中状态。例如,这允许“重置”表单。
属性不同的示例:
console.log([a.checked, a.getAttribute("checked")]);
a.checked = false;
console.log([a.checked, a.getAttribute("checked")]);
console.log([b.checked, b.getAttribute("checked")]);
b.checked = true;
console.log([b.checked, b.getAttribute("checked")]);
<input type=checkbox id=a checked>
<input type=checkbox id=b>
无论如何,您可以使用 Chrome 开发工具中的“属性”选项卡来查看其他属性。
(在 Firefox 中,这是在右键单击 > 显示 DOM 属性下,但您必须首先选择正确的 iframe。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)