繁体   English   中英

我想将每个单选按钮重置为未选中,但我的代码不起作用

[英]I want to reset every radiobutton to unchecked, but my code doesn't work

对于 javascript 课程,我正在尝试完成挑战。 单击按钮后,我想取消选中每个选中的单选按钮。 下面是我的代码:

let result = 0;
function checkResult() {
  if (document.getElementById("quiz1a").checked == true) {
      result++;
  }
  if (document.getElementById("quiz2c").checked == true) {
      result++;
  }
  if (document.getElementById("quiz3a").checked == true) {
      result++;
  }
  if (document.getElementById("quiz4a").checked == true) {
      result++;
  }
  document.querySelectorAll('input[type="radio"]').checked = false;
  console.log(result);
  result = 0;
}
document.querySelectorAll('input[type="radio"]')

返回一个数组。 您应该使用forEach迭代其元素。

由于这是一门课程,我不会为你拼写出来;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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