首页javascriptradiobuttonJavascript Form - 如何确定单选按钮是否处于选中状态或未选中状态

Javascript Form - 如何确定单选按钮是否处于选中状态或未选中状态

我们想知道如何确定单选按钮是否处于选中状态或未选中状态。


<html>
<body>
    <script language="JavaScript">
    function checkButton(){
        if(document.form1.button1.checked == true){
            console.log("Box1 is checked");
        } else if(document.form1.button2.checked == true){
            console.log("Box 2 is checked");
        }
    }
    </script>
    <form name="form1">
        <input type="radio" name=button1>Box 1
        <br>
        <input type="radio" name=button2 CHECKED>Box 2
        <br>
        <INPUT type="button" value="Get Checked" onClick='checkButton()'>
    </form>
</body>
</html>