js来回显示隐藏

<html>
    <head>
        <meta charset="utf-8">
        <title>隐藏和显示</title>
        <style type="text/css">
            #sidebar_x {
                width: 200px;
                height: 100px;
                line-height: 100px;
                text-align: center;
                background-color: green;
            }
        </style>
        <script type="text/javascript">
            function Show_Hidden(obj) {
                if(obj.style.display == "block") {
                    obj.style.display = 'none';
                } else {
                    obj.style.display = 'block';
                }
            }
            window.onload = function() {
                var olink = document.getElementById("show_hidden");
                var odiv = document.getElementById("sidebar_x");
                olink.onclick = function() {
                    Show_Hidden(odiv);
                    return false;
                }
            }
        </script>
    </head>

    <body>
        <a href="#" id="show_hidden">显示隐藏切换</a>
        <div id="sidebar_x" style="display:none">崩卡拉卡</div>
    </body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_35327397/article/details/79077929