为了账号安全,请及时绑定邮箱和手机立即绑定

有问题啊 动态实现上,切换tab不成功

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" http-equiv="content-type" content="text/html">
    <title>Title</title>
 <!--[if lt IE 7]>
    <style>
        .ficon{font-family:'fontello'}
    </style>
    <![endif]-->
 <style type="text/css">
 @font-face {
            font-family: 'fontello';
            src: url('font/fontello.eot');
            src: url('font/fontello.eot#iefix') format('embedded-opentype'),
            url('font/fontello.woff') format('woff'),
            url('font/fontello.ttf') format('truetype'),
            url('font/fontello.svg#fontello') format('svg');
            font-weight: normal;
            font-style: normal;
        }
        .ficon,[class^="ficon-"],[class^="ficon-"]:before,[class*=" ficon-"]:before {
            font-family: "fontello";
            font-size: 15px;
            font-style: normal;
            font-weight: normal;
            speak: none;
            display: inline-block;
            text-decoration: inherit;
            width: 1em;
            margin-right: .2em;
            text-align: center;
            font-variant: normal;
            text-transform: none;
            line-height: 1em;
            margin-left: .2em;
        }
        body{
            font: 12px/1.5 tahoma,arial,sans-serif;
        }
        ul{
            list-style: none;
            display: block;
        }
        ul,li{
            margin: 0px;
            padding: 0px 0 0 0;
        }
        .search-list li a{
            text-decoration: none;
            color: #6c6c6c;
        }
        .search-list .select{
            background: #f6f6f6;
            display: block;
        }
        .search-list{
            position: absolute;
            top: 3px;
            left: 3px;
            background-color: white;
            width: 71px;
            height: 36px;
            overflow: hidden;
            border-left: 1px  solid #f6f6f6;
            border-right: 1px solid #e5e5e5;
        }
        .search-list li{
            display: none;
            height: 35px;
            line-height: 35px;
            overflow:hidden;
            text-align: center;
        }
        .trigger-hover{
            height: auto;
        }
        .trigger-hover li{
            display: block;
        }
        .search-container{
            position: relative;
        }
        .search-tips{
            float: right;
            padding: 3px 15px;
        }
        .search-btn{
            float: right;
        }
        .search-tips a{
            color: #333333;
            text-decoration: none;
        }
        .btn-search{
            background: url("search.png") 0px -152px;
            width: 120px;
            height: 43px;
            border: 0px;
            cursor: pointer;
        }
        .search-key{
            height: 39px;
            line-height: 39px;
            padding: 2px 0 2px 79px;
            overflow: hidden;
            background-color: orangered;
        }

        .search-key input{
            height: 35px;
            width: 100%;
            border: 0px none;
            outline: none;
            background-color: #ffffff;
        }
        .search-key i{
            position: absolute;
            top:14px;
            left: 86px;
            z-index: 2;
            color: #333333;
        }
        .iconfont{
            font-family: iconfont;
            font-size: 12px;
            font-style: italic;
        }
    </style>
</head>
<body>
    <div class="search-container">
        <div class="search-list" id="search-tap">
            <ul>
                <li id="tab1" class="select"><a href="">宝贝</a></li>
                <li id="tab2" class=" "><a href="">店铺</a></li>
            </ul>
        </div>
        <div class="search-pannel">
            <form action="">
                <div class="search-tips">
                    <a href="">
 高级<br>搜索
                    </a>
                </div>
                <div class="search-btn">
                <button class="btn-search" type="submit"></button>
                </div>
                <div class="search-key">
                    <input type="text" x-webkit-speech>
                    <i class="ficon" >
 &#xe800;
 </i>
                </div>

            </form>
        </div>
    </div>
    <script>
 var getDOM=function(id){
 return document.getElementById(id);
        }
 var addHandler=function (element,type,handler) {
 var id=getDOM(element)||document;
 if (id.addEventListener){
 id.addEventListener(type,handler,false);//这个跟下面on事件相比,优势是元素可以添加多个事件
 }else if (id.attachEvent){
 id.attachEvent('on'+type,handler);
            }else{
 id['on'+type]=handler;
            }
        }
 addHandler('search-tap','mouseover',function () {
 this.className+=' trigger-hover';
        });
 addHandler('search_tab','mouseout',function(){
 this.className=' search-list';//注意:类名前加空格
 });
 addHandler('tab1','mouseover',function () {
 if(this.className.indexOf('select')<0){
 this.className='select';
            }
        });
 addHandler('tab1','mouseout',function () {
 this.className=" ";
        });
 addHandler('tab1','click',function () {
 getDOM('search-tap').className='search-list';

        });
 addHandler('tab2','mouseover',function () {
 if(this.className.indexOf('select')<0){
 this.className='select';
            }
        });
 addHandler('tab2','mouseout',function () {
 this.className=" ";
        });
 addHandler('tab2','click',function () {
 getDOM('search-tap').className='search-list';

 getDOM('tab1').className=" ";
        });
 </script>
</body>
</html>


正在回答

2 回答

点击后不也触发了移开的事件么那么class也清空了

0 回复 有任何疑惑可以回复我~
#1

qq_蔷薇之恋_0 提问者

非常感谢!
2016-10-17 回复 有任何疑惑可以回复我~

应该是可以切换的,只不过在点击li里面的a标签之后,浏览器自动刷新,将你原来li的样式自动设为默认的了。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
搜索框制作
  • 参与学习       66003    人
  • 解答问题       463    个

本课程从简入深讲解搜索框的制作,学习JQ与JS实现Ajax技术的不同点

进入课程

有问题啊 动态实现上,切换tab不成功

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号