javascript - removeAttribute 删除 "disabled"但不删除 "checked"

标签 javascript html

我的 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/

相关文章:

javascript - 制作点击事件只影响父类的 child ?

javascript - PHP 正在 HTML 中插入不在 echo 字符串中的字符

javascript - 根据文本输入更改具有特定类的所有元素

asp.net - 如何从 Javascript 将 TableRow/TableCell 添加到 ASP.NET 表?

javascript - 如何根据从 DOM 接收到的键更新状态数组中的某些对象

javascript - 是否可以在单击其他按钮时显示按钮的 Bootstrap 弹出窗口?

html - 我如何养 child (位置:fixed) below the parent (`position:fixed` )?

c# - 如何显示和隐藏 html 字段集以及从后面的 Asp.Net 代码设置图例文本

javascript - 覆盖整个屏幕的弹出窗口

javascript - 如何在html中获取PHP echo值,使其与其他输入相同?