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

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

 

posted @ 2019-08-28 14:57  鱼七姑娘  阅读(380)  评论(0编辑  收藏  举报