| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4036 人关注过本帖
标题:JS选项卡自动切换怎么写?
只看楼主 加入收藏
yoooos
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-6-18
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
JS选项卡自动切换怎么写?
要攺一下link的路径
选项卡怎么切换.rar (1.84 KB)

程序代码:
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>选项卡</title>
    <link rel="stylesheet" type="text/css" href="css/选项卡.css"/>
    <script type="text/javascript">
        window.onload = function(){
            var oUl1 = document.getElementsByClassName('menu')[0];
            var oUl2 = document.getElementsByClassName('menu')[1];
            var aLi1 = oUl1.children;        //ka1的li集合           

            var aLi2 = oUl2.children;        //ka2的li集合
            //arr:选项卡节点集合. parent_id : 与选项卡相关联的DIV的父级ID.Auto:自动轮换开关(0/1),time:轮换时间设置;
            function onmouseover(arr,parent_id,Auto,times){               

                var oParent =  document.getElementById(parent_id);
                var aParent = oParent.getElementsByTagName('div');
                var fnA = function (){
                    for (var i = 0; i < arr.length; i++) {
                        arr[i].index = i;
                        arr[i].onmouseover = function (){
                            for (var i = 0; i < arr.length; i++) {
                                arr[i].className = 'tabs';
                                aParent[i].style.display = 'none';
                            }
                            this.className = ' tabs over';
                            aParent[this.index].style.display = 'block';
                        }
                    }
                }
                var t = null;        //定时器
                if(Auto){
                    //当鼠标离开选项卡区域2秒后,激活定时器
                    oParent.onmouseout = function (){                       

                        setTimeout(function (){
                            /*
                             *这里要怎么写?
                             *

                             * t = setInterval.....

                             *

                             * */
                        },2000);
                    }
                    //鼠标在选项卡上时,禁用定时器,并执行fnA()
                    oParent.onmouseover = function (){
                        clearInterval(t);
                        fnA();
                    }
                } else {    //设置为手动时
                    fnA();
                }
            }
            onmouseover(aLi1,'ka1',1,3000);
            onmouseover(aLi2,'ka2',0);
        }
    </script>
</head>
<body>
    <div id="container" class="container">
        <div id="ka1" class="ka">
            <ul class="menu">
                <li class="tabs over">AAA</li>
                <li class="tabs">BBB</li>
                <li class="tabs">CCC</li>
                <li class="tabs">DDD</li>
            </ul>
            <div class="main" style="display: block;">AAA</div>
            <div class="main">BBB</div>
            <div class="main">CCC</div>
            <div class="main">DDD</div>
        </div>
        <div id="ka2" class="ka">
            <ul class="menu">
                <li class="tabs over">AAA</li>
                <li class="tabs">BBB</li>
                <li class="tabs">CCC</li>
                <li class="tabs">DDD</li>
            </ul>
            <div class="main" style="display: block;">AAA</div>
            <div class="main">BBB</div>
            <div class="main">CCC</div>
            <div class="main">DDD</div>
        </div>
    </div>
</body>
</html>





[此贴子已经被作者于2016-6-18 12:01编辑过]

搜索更多相关主题的帖子: javascript title 
2016-06-18 11:50
leeqihero
Rank: 3Rank: 3
等 级:论坛游侠
威 望:7
帖 子:122
专家分:135
注 册:2016-3-24
收藏
得分:10 
<head>
<meta charset="UTF-8" />
<style>
@charset "utf-8";
*{
    margin: 0px;
    padding: 0px;
}
body{
    width: 980px;
    min-height: 700px;
    font-size: 20px;
    font-weight: 700;
}
#container {
    margin: 30px auto;
}
#container > div{
    float: left;
    margin: auto 20px;
}
.menu{
    list-style: none;
   
}
.ka{
    width: 403px;
    height: 330px;
    border: 1px solid #ccc;
}
.tabs{
    width: 100px;
    height: 30px;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    float: left;
    text-align: center;
    line-height: 30px;
}
.tabs:last-child{
    border-right: none;
}
.main{
    width: 100%;
    height: 300px;
    margin-bottom: 30px;
    /*background-color: #CCCCCC;*/
    clear: both;
    text-align: center;
    display: none;
}
.over{
    /*background-color: greenyellow;*/
    border-bottom: none;
    border-left: none;
    border-right: 1px solid #ccc;
    border-top: 1px solid #a40000;
}
</style>
<script>
onload=function(){
    var oUl1 = document.getElementsByClassName('menu')[0];
    var oUl2 = document.getElementsByClassName('menu')[1];
    var aLi1 = oUl1.children;        //ka1的li集合            
    var aLi2 = oUl2.children;        //ka1的l2集合
            //arr:选项卡节点集合. parent_id : 与选项卡相关联的DIV的父级ID.Auto:自动轮换开关(0/1),time:轮换时间设置;
    function onmouseover(arr,parent_id,Auto,times){
        var oParent =  document.getElementById(parent_id);
        var aParent = oParent.getElementsByTagName('div');
        var fnA = function (){
            for (var i = 0; i < arr.length; i++) {
                arr[i].index = i;
                arr[i].onmouseover = function (){
                    for (var i = 0; i < arr.length; i++) {
                        arr[i].className = 'tabs';
                        aParent[i].style.display = 'none';
                    }
                    this.className = ' tabs over';
                    aParent[this.index].style.display = 'block';
                }
            }
        }
var t = null;        //定时器
if(Auto){
                    //当鼠标离开选项卡区域2秒后,激活定时器
    oParent.onmouseout = function (){
        setTimeout(function (){
                            /*
                             *这里要怎么写?
                             *
                             *
                             *
                             * */
        },2000);
    }
                    //鼠标在选项卡上时,禁用定时器,并执行fnA()
    oParent.onmouseover = function (){
        clearInterval(t);
        fnA();
    }
}
else {    //设置为手动时
    fnA();
}
}
onmouseover(aLi1,'ka1',1,3000);
onmouseover(aLi2,'ka2',0);
}
</script>
</head>
<body>
    <div id="container" class="container">
        <div id="ka1" class="ka">
            <ul class="menu">
                <li class="tabs over">AAA</li>
                <li class="tabs">BBB</li>
                <li class="tabs">CCC</li>
                <li class="tabs">DDD</li>
            </ul>
            <div class="main" style="display: block;">AAA</div>
            <div class="main">BBB</div>
            <div class="main">CCC</div>
            <div class="main">DDD</div>
        </div>
        <div id="ka2" class="ka">
            <ul class="menu">
                <li class="tabs over">AAA</li>
                <li class="tabs">BBB</li>
                <li class="tabs">CCC</li>
                <li class="tabs">DDD</li>
            </ul>
            <div class="main" style="display: block;">AAA</div>
            <div class="main">BBB</div>
            <div class="main">CCC</div>
            <div class="main">DDD</div>
        </div>
    </div>
</body>
</html>
2016-06-20 20:43
熊孩子canfly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-6-29
收藏
得分:0 
这么多代码,,用插件呐、、、几行搞定
2016-06-29 10:43
快速回复:JS选项卡自动切换怎么写?
数据加载中...
 
   



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

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