天天看點

借用滑鼠指定的對象實作動态顯示和隐藏菜單

<!DOCTYPE html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title></title>

    <style type="text/css">

        #p > li {

            list-style-type:none;

            float:left;

            width:80px;

            cursor:pointer;

        }

        .hide {

            display: none;

        .show {

            position: absolute;

            list-style-type: none;

            display: block;

            margin: 0;

            padding: 0;

            background-color: Gray;

    </style>

    <script>

        //document.getElementsByTagName

        function show(li)

        {

            var ul = l1.getElementsByTagName("ul");

            for (var i = 0; i < ul.length; i++)

            {

                //alert("執行到這了");

               // alert(ul.innerText);

                if (ul[i].className == "hide")

                {

                    ul[i].className = "show"

                }

            }

    </script>

</head>

<body>

    <ul id="p">

        <li id="l1" onmousemove="show(this)">

            檔案

            <ul class="hide" id="memu">

                <li>建立</li>

                <li>儲存</li>

                <li>另存為</li>

                <li>退出</li>

            </ul>

        </li>

        <li>

            編輯

            插入

                <li>儲存</li> 

            窗體

            幫助

    </ul>

</body>

</html>