为了账号安全,请及时绑定邮箱和手机立即绑定

为什么使用switch语句不行?

 var ho=document.getElementsByName("hobby"); switch(j){ case 1: ho[0].checked=true; break; ase 2: ho[1].checked=true; break; case 3: ho[2].checked=true; break; case 4: ho[3].checked=true; break; case 5: ho[4].checked=true; break; case 6: ho[5].checked=true; break; default: }

正在回答

2 回答

            switch(j)
            {
                case "1":
                    var hobby = document.getElementById("hobby1");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                 case "2":
                    var hobby = document.getElementById("hobby2");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                case "3":
                    var hobby = document.getElementById("hobby3");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                case "4":
                    var hobby = document.getElementById("hobby4");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                case "5":
                    var hobby = document.getElementById("hobby5");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                case "6":
                    var hobby = document.getElementById("hobby6");
                    if (false == hobby.checked)
                    {
                        hobby.checked = true;
                    }
                    break;
                default:
                    var j = document.getElementById("wb");
                    j.value="";
                    j.placeholder="请输入1-6之间的数字";
                    alert("请输入1-6之间的数字");
                    
                    break;
            }

当然可以了。

0 回复 有任何疑惑可以回复我~

ase 2 这里少了一个子母C

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么使用switch语句不行?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信