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

我这个为什么没有隐藏?

我这个为什么没有隐藏?

19990000 2017-10-09 15:01:47
<!DOCTYPE html> <html> <head>    <meta charset="UTF-8">    <title>二级联动</title>    <style>        *{            margin:0;            padding:0;            font-size:12px;        }        .wrap{            width:800px;            margin:0 auto;            text-align: center;        }        /*选项*/ .student{            margin-top:50px;        }        .yes,.no{            margin:0 50px;            vertical-align: middle;        }        .in,.out{            margin-top:20px;        }        .in select{            margin:0 20px;            width:130px;            height:30px;            box-sizing: border-box;        }        .out input{            width:250px;            height:30px;            box-sizing: border-box;        }        label{            font-weight: bold;        }        .out{            display: none;        }    </style> </head> <body>    <div>        <!--选项--> <div>            <label for="yes">                <input type="radio" name="sec" id="yes" checked="checked">                在校生            </label>            <label for="no">                <input type="radio" name="sec" id="no">                非在校生            </label>        </div>        <!--在线生选项--> <div id="in">            <label for="city">                学校                <select name="city" id="city">                    <option value="">请选择</option>                </select>                <select name="school" id="school">                    <option value="">请选择</option>                </select>            </label>        </div>        <!--非在校生--> <div id="out">            <label for="job">                就业单位                <input type="text" name="job" id="job">            </label>        </div>    </div> </body> <script>    var $ =function(id){        return document.getElementById(id);    };        function select(){        if($("yes").checked === true){            $("in").style.display = "block";            $("out").style.display = "none";        }else if($("no").checked === true){            $("in").style.display = "none";            $("out").style.display = "block";        }    }    select(); </script> </html>
查看完整描述

3 回答

已采纳
?
山_3

TA贡献3条经验 获得超0个赞

你应该把你的函数绑定到事件上去而不是直接执行   这样能在选中后触发事件

查看完整回答
反对 回复 2017-10-09
?
王二小_

TA贡献17条经验 获得超15个赞

我认为还是写css样式隐藏比较好点

查看完整回答
反对 回复 2017-10-09
  • 3 回答
  • 1 关注
  • 1719 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信