点击按钮,设置div显示和隐藏div

<input type="button" value="设置div隐藏" id="btn18" />
        <input type="button" value="设置div显示" id="btn19" />
        <div id="dv" style="width: 200px;height: 200px;background-color:pink"></div>
        <script type="text/javascript">
            //凡是css中这个属性是对个单词的写法,在jsDOM操作的时候,把-去掉,
            //后面单词的首字母大写即可.比如:background-color 写成 backgroundColor
            function my$(id) {
                return document.getElementById(id);
            }
            my$("btn18").onclick=function(){
                my$("dv").style.display="none";
            };
            my$("btn19").onclick=function(){
                my$("dv").style.display="block";
            };
        </script>

猜你喜欢

转载自www.cnblogs.com/zhangDY/p/11424095.html