我尝试在选择单选按钮时提交表单但未成功 javascript

I'm trying to submit a form when selecting a radio button and not successful javascript

这是我最后一次尝试,我没有成功。

if(document.querySelectorAll("input[name='myRadioButton']").checked) {   
  alert("checked");
}

对 JavaScript 专家来说一定很简单。 为什么JavaScript这么难?

请不要 jQuery。

您可以像这样使用事件侦听器来处理输入更改:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="radio" name="myradio" />
    <input type="radio" name="myradio" />
    <input type="radio" name="myradio" />
  </body>
</html>
<script>
  let radio = document.getElementsByName("myradio");

  for (let i = 0; i < radio.length; i++) {
    radio[i].addEventListener("input", () => {
      alert("checked");
    });
  }
</script>