什么是'menu2'的实现

时间:2013-05-18 01:56:26

标签: javascript css html5

在下面的下拉菜单中,有onmouseover="openelement('menu2')" , onmouseover="openelement('menu3')"等调用的java脚本函数。我无法理解这个'menu2&#39 , 'menu3'是什么。有人可以解释一下这个。整个计划如下。

        下拉菜单CSS& JS

    <!--The CSS code.-->
    <style type="text/css" media="screen">

            #nav {
                margin: 0;
                padding: 0;
            }

            #nav li {
                list-style: none;
                float: left;
            }

            #nav li a {
                display: block;
                margin: 0 1px 0 0;
                padding: 4px 10px;
                width: 80px;
                background: lavender;
                color: black;
                text-align: center;
                text-decoration:none;
            }

            #nav li a:hover {
                background: grey;
            }

            #nav ul {
                position: absolute;
                visibility: hidden;
                margin: 0;
                padding: 0;
                border: 1px solid #ffffff
            }

            #nav  ul li a{
                    position: relative;
                    margin: 0;
                    padding: 5px 10px;
                    width: 80px;
                    text-align: left;
                    background: lavender;
                    color: #000000;
                }   

            #nav li ul li {
                clear: both;
            }
    </style>
    <!--The end of the CSS code.-->

    <!--The Javascript menu code.-->
    <script type="text/javascript">
        //variables' declaration

        var timeout = 500;
        var timer   = 0;
        var item    = 0;

        //function for opening of submenu elements
        function openelement(num)
        {    
            keepsubmenu()
            //checks whether there is an open submenu and makes it invisible
            if(item){ item.style.visibility = 'hidden';}
                //shows the chosen submenu element
                item = document.getElementById(num);
                item.style.visibility = 'visible';
        }

        // function for closing of submenu elements
        function closeelement()
        {
            //closes the open submenu elements and loads the timer with 500ms
            timer = window.setTimeout("if(item) item.style.visibility = 'hidden';",500);
        }

        //function for keeping the submenu loaded after the end of the 500 ms timer
        function keepsubmenu()
        {
            if(timer){
                window.clearTimeout(timer);
                timer = null;
            }
        }

        //hides the visualized menu after clicking outside of its area and expiring of the loaded timer
        document.onclick = closeelement;

    </script>
    <!--END of CSS code-->

</head>
<body>
    <!--HTML code for the menu -->
    <ul id="nav">
        <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#">Home</a>
        </li>
        <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#" onmouseover="openelement(&#39;menu2&#39;)" onmouseout="closeelement()">Tutorials</a>
            <ul id="menu2" onmouseover="keepsubmenu()" onmouseout="closeelement()" style="visibility: hidden; ">
                <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#">CSS</a></li>
                <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#">Flash</a></li>
            </ul>
        </li>
        <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#" onmouseover="openelement(&#39;menu3&#39;)" onmouseout="closeelement()">More</a>
            <ul id="menu3" onmouseover="keepsubmenu()" onmouseout="closeelement()">
               <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#">About Us</a></li>
                <li><a href="http://www.sci.sjp.ac.lk/lms/file.php/233/dropDownJs.html#">Contact Us</a></li> 
            </ul>
        </li>
    </ul>
    <div style="clear:both"></div>
    <!--the end of the HTML code for the menu -->

2 个答案:

答案 0 :(得分:3)

39是撇号的ASCII码,&#39;是将ASCII字符插入HTML的语法

此语法主要用于插入在HTML / JavaScript中具有意义的字符(以及防止跨站点脚本攻击) - 例如<>个字符

在你的情况下你应该更换&amp;#39;带有撇号(')的事件处理程序内部的事件,因此它在Javascript

中的作用

答案 1 :(得分:1)

这只是一个撇号,可能来自糟糕的复制/粘贴。例如,如果您在Word中编写代码,或者从应用特殊格式的文本区域复制,则会发生这种情况。应该是单引号,因为函数需要一个字符串。

"openelement('menu3')"