How can I check whether a radio button is selected with JavaScript?

前端 未结 28 2442
面向向阳花
面向向阳花 2020-11-22 00:58

I have two radio buttons within an HTML form. A dialog box appears when one of the fields is null. How can I check whether a radio button is selected?

28条回答
  •  被撕碎了的回忆
    2020-11-22 01:36

    Try

    [...myForm.sex].filter(r=>r.checked)[0].value
    

    function check() {
      let v= ([...myForm.sex].filter(r=>r.checked)[0] || {}).value ;
      console.log(v);
    }
    Men Woman

提交回复
热议问题