| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1133 人关注过本帖
标题:怎么把光标离开下拉菜单时,把下拉菜单隐藏?
只看楼主 加入收藏
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:7 
怎么把光标离开下拉菜单时,把下拉菜单隐藏?
<html>
    <head>
        <style>
            *{margin:0;padding:0;}
            ul{
                list-style:none;
            }
            #menu{
                width:860px;
                margin:55px auto;
                font-size:13px;
                border:1px solid orange;
                overflow:hidden;
            }
            #tabMenu{
                background:orange;
                height:30px;
                width:870px;
            }
            #tabMenu li{
                float:left;
                line-height:30px;
                width:143px;
                background:#fdceff;
                margin-right:1px;
                text-align:center;
            }
            #tabMenu .bgcaption{
                background:#fbb7fd;
                color:#fff;
                font-weight:bold;
            }
            #tabContent{
                width:860px;
                position:relative;
                height:100px;
            }
            #tabContent ul{
                background:#fbb7fd;
                width:144px;
                position:absolute;
                top:0;
                left:0;
            }
            #tabContent .current{
                display:block;
            }
            #tabContent .normal{
                display:none;
            }
        </style>

        <script type="text/javascript">
            function tabChange(num){
                var tabMenu = document.getElementById("tabMenu");
                var tablist = tabMenu.getElementsByTagName("li");
                for(var i=0; i<tablist.length; i++){
                    var m = i+1;
                    if(i == num){
                        document.getElementById("list_"+m).className ="current";
                        tablist[i].className = "bgcaption";
                        document.getElementById("list_"+m).style.left = num*144+"px";
                    }
                    else{
                        document.getElementById("list_"+m).className ="normal";
                        tablist[i].className = ""                        
                    }
                    var content = document.getElementById("tabContent")
                    var list = content.getElementsByTagName("ul")
                    list[i].oumouseout = function(){
                        this.className ="normal";
                    }
                }
            }
        </script>
    </head>


    <body>
        <div id="menu">
            <div id="tabMenu">
                <ul>
                    <li onmouseover="tabChange(0)">新闻</li>
                    <li onmouseover="tabChange(1)">游戏</li>
                    <li onmouseover="tabChange(2)">聊天</li>
                    <li onmouseover="tabChange(3)">产品</li>
                    <li onmouseover="tabChange(4)">音乐</li>
                    <li onmouseover="tabChange(5)">论坛</li>                    
                </ul>
            </div>

            <div id="tabContent">
                <ul id="list_1">
                    <li><a href="">网易新闻</a></li>
                    <li><a href="">新浪新闻</a></li>
                    <li><a href="">腾讯新闻</a></li>
                    <li><a href="">搜狐新闻</a></li>                    
                </ul>
                <ul id="list_2" class="normal">
                    <li><a href="">网络游戏</a></li>
                    <li><a href="">单机游戏</a></li>
                    <li><a href="">小游戏</a></li>
                </ul>
                <ul id="list_3" class="normal">
                    <li><a href="">QQ即时通</a></li>
                    <li><a href="">msn即时通</a></li>
                </ul>
                <ul id="list_4" class="normal">
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>                    
                </ul>
                <ul id="list_5" class="normal">
                    <li><a href="">在线试听</a></li>
                    <li><a href="">下载歌词</a></li>                    
                </ul>
                <ul id="list_6" class="normal">
                    <li><a href="">天涯社区</a></li>
                    <li><a href="">猫扑论坛</a></li>                    
                </ul>
            </div>
        </div>
    </body>
</html>



[ 本帖最后由 rao3324180 于 2010-8-8 16:37 编辑 ]
搜索更多相关主题的帖子: 光标 菜单 隐藏 
2010-08-08 16:31
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
收藏
得分:0 
没人回答吗
2010-08-08 19:23
gulimeksoft
Rank: 4
等 级:业余侠客
威 望:4
帖 子:53
专家分:208
注 册:2010-8-5
收藏
得分:0 
程序代码:
<html>
    <head>
        <style>
            *{margin:0;padding:0;}
            ul{
                list-style:none;
            }
            #menu{
                width:860px;
                margin:55px auto;
                font-size:13px;
                border:1px solid orange;
                overflow:hidden;
            }
            #tabMenu{
                background:orange;
                height:30px;
                width:870px;
            }
            #tabMenu li{
                float:left;
                line-height:30px;
                width:143px;
                background:#fdceff;
                margin-right:1px;
                text-align:center;
            }
            #tabMenu .bgcaption{
                background:#fbb7fd;
                color:#fff;
                font-weight:bold;
            }
            #tabContent{
                width:860px;
                position:relative;
                height:100px;
            }
            #tabContent ul{
                background:#fbb7fd;
                width:144px;
                position:absolute;
                top:0;
                left:0;
            }
            #tabContent .current{
                display:block;
            }
            #tabContent .normal{
                display:none;
            }
        </style>

        <script type="text/javascript">
            function tabChange(num){
                var tabMenu = document.getElementById("tabMenu");
                var tablist = tabMenu.getElementsByTagName("li");
                for(var i=0; i<tablist.length; i++){
                    var m = i+1;
                    if(i == num){
                        document.getElementById("list_"+m).className ="current";
                        tablist[i].className = "bgcaption";
                        document.getElementById("list_"+m).style.left = num*144+"px";
                    }
                    else{
                        document.getElementById("list_"+m).className ="normal";
                        tablist[i].className = ""                       
                    }
                 
      
                }
            }
    function hideall(){
      var tabMenu = document.getElementById("tabContent");
                var tablist = tabMenu.getElementsByTagName("ul");
                for(var i=0; i<tablist.length; i++){
                    var m = i+1;
                   
                        tablist[i].className ="normal";
                     
                    }
    }
    function tag(element) {
      var e;
      if (element == null) {
        e = window.event.srcElement;
      } else {
        e = element;
      }
    if(e.tagName!="A"&&e.tagName!="LI"){hideall();}
    }
        </script>
    </head>


    <body onmouseover="tag()">
        <div id="menu" >
            <div id="tabMenu" >
                <ul>
                    <li onmouseover="tabChange(0)">新闻</li>
                    <li onmouseover="tabChange(1)">游戏</li>
                    <li onmouseover="tabChange(2)">聊天</li>
                    <li onmouseover="tabChange(3)">产品</li>
                    <li onmouseover="tabChange(4)">音乐</li>
                    <li onmouseover="tabChange(5)">论坛</li>                   
                </ul>
            </div>

            <div id="tabContent" >
                <ul id="list_1">
                    <li><a href="">网易新闻</a></li>
                    <li><a href="">新浪新闻</a></li>
                    <li><a href="">腾讯新闻</a></li>
                    <li><a href="">搜狐新闻</a></li>                   
                </ul>
                <ul id="list_2" class="normal">
                    <li><a href="">网络游戏</a></li>
                    <li><a href="">单机游戏</a></li>
                    <li><a href="">小游戏</a></li>
                </ul>
                <ul id="list_3" class="normal">
                    <li><a href="">QQ即时通</a></li>
                    <li><a href="">msn即时通</a></li>
                </ul>
                <ul id="list_4" class="normal">
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>
                    <li><a href="">暂无!</a></li>                   
                </ul>
                <ul id="list_5" class="normal">
                    <li><a href="">在线试听</a></li>
                    <li><a href="">下载歌词</a></li>                   
                </ul>
                <ul id="list_6" class="normal">
                    <li><a href="">天涯社区</a></li>
                    <li><a href="">猫扑论坛</a></li>                   
                </ul>
            </div>
        </div>
    </body>
</html>
用tagName
2010-08-08 23:26
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
收藏
得分:0 
3楼的我试了,还是不行
2010-08-09 01:18
gulimeksoft
Rank: 4
等 级:业余侠客
威 望:4
帖 子:53
专家分:208
注 册:2010-8-5
收藏
得分:0 
你用IE试试,其他的我不晓得,IE是肯定可以的
2010-08-09 01:49
foktime
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:奥斯维辛
等 级:贵宾
威 望:35
帖 子:795
专家分:2742
注 册:2009-9-4
收藏
得分:0 
程序代码:
                <ul id="ul_id">
                    <li onmouseover="tabChange(0)">新闻</li>
                    <li onmouseover="tabChange(1)">游戏</li>
                    <li onmouseover="tabChange(2)">聊天</li>
                    <li onmouseover="tabChange(3)">产品</li>
                    <li onmouseover="tabChange(4)">音乐</li>
                    <li onmouseover="tabChange(5)">论坛</li>                   
                </ul>
程序代码:
<script>
    var objarr = document.getElementById('ul_id').getElementsByTagName("li");
    for (var i = 0; i < objarr.length; i++) {
        if (objarr[i].tagName.toLowerCase() == "li") {
            objarr[i].onmouseout = function() {
                for(var j=0;j<6;j++){
                    document.getElementById("list_" + (j+1)).className = "normal";
                }
            }
        }
    }
</script>
js放html下面
2010-08-09 11:23
rao3324180
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-6-15
收藏
得分:0 
以下是引用foktime在2010-8-9 11:23:28的发言:

                 
                    新闻
                    游戏
                    聊天
                    产品
                    音乐
                    论坛                    
                 
    var objarr = document.getElementById('ul_id').getElementsByTagName("li"); 
    for (var i = 0; i js放html下面
也不行,光标移动到下拉菜单就隐藏了.我要是光标离开下拉菜单隐藏掉啊
2010-08-09 19:55
foktime
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:奥斯维辛
等 级:贵宾
威 望:35
帖 子:795
专家分:2742
注 册:2009-9-4
收藏
得分:10 
我几乎是郁闷了,代码都给出了,你把事件换个地方不就行了?学东西别太死
2010-08-10 08:03
快速回复:怎么把光标离开下拉菜单时,把下拉菜单隐藏?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025165 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved