我的 js 代码中有两行:
document.getElementsByName('group')[0].removeAttribute('disabled');
document.getElementsByName('group')[0].removeAttribute('checked');
第一个字符串效果很好,但第二个字符串什么也没做。我想遵循 html5 风格,因此为 checked
设置 false
值不是我的选择。
顺便说一句,我正在寻找设置空属性的方法。其他主题中的方法(例如 .setAttribute(attr_name,"");
)完全按照其用途:使用空字符串值创建 attr,而不仅仅是 attr。我该怎么办?
最佳答案
checked
是一个属性,您应该这样对待它:
document.getElementsByName('group')[0].checked = false;
关于javascript - removeAttribute 删除 "disabled"但不删除 "checked",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37492632/