最后切换实现不了
看了好几遍最后切换一直没实现,求指导,求代码
看了好几遍最后切换一直没实现,求指导,求代码
2016-09-22
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>淘宝搜索框</title>
<link type="text/css" rel="stylesheet" href="css/first.css">
<style type="text/css">
@font-face{font-family:iconfont;src:url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.eot);
src: url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.eot?#iefix) format("embedded-opentype"),
url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.woff) format("woff"),
url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.ttf) format("truetype"),
url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.svg#uxiconfont) format("svg");}/*字符集图标*/
*{padding: 0;margin:0;}
body{font:12px/1.5 tahoma,arial,sans-serif;}
a{text-decoration:none;}
.search-container{position:relative;}
.search-tips,.search-button{float:right;}
.search-tips{padding:3px 0 0 15px;}
.search-tips a{color:#ccc;}
.btn-search{
background:url(http://gtms01.alicdn.com/tps/i1/T1qyj8Fc8aXXc4E9bI-400-300.png);
width:100px;
height:45px;
background-position:0 -244px;
border:none;
cursor:pointer;
}
.search-common-panel{
height:39px;
background-color:#f50;
overflow:hidden;
padding:3px 0 3px 77px;
}
.search-common-panel input{
height:39px;
line-height:39px;
width:100%;
border:0 none;
outline:0;
background-color:#fff;
}
.search-common-panel i{
position:absolute;
top:14px;
left:86px;
z-index:2;
color:#ccc;
}
.iconfont{
font-family:iconfont;
font-size:12px;
font-style:normal;
}
ul{list-style:none;}
.search-list{
position:absolute;top:3px;left:3px;width:72px;height:39px;overflow:hidden;
background-color:#FFF;
border-left:1px solid #f6f6f6;
border-right:1px solid #E5E5E5;
}
.search-list li{ display:none; height:39px; line-height:39px;overflow:hidden;text-align:center;}
.search-list li a{color:#6C6C6C;}
.search-list .selected{ background:#F6F6F6;display:block;}
.trigger-hover{height:auto;}
.trigger-hover li{display:block;}
</style>
</head>
<body>
<div class="search-container">
<div class="search-list" id="search-tab">
<ul>
<li id="tab_1" class="selected"><a href="#">宝贝</a></li>
<li id="tab_2"><a href="#">商铺</a></li>
</ul>
</div>
<div class="search-pannel">
<form>
<div class="search-tips">
<a href="#">高级<br>搜索</a>
</div>
<div class="search-button">
<button class="btn-search" type="submit"></button>
</div>
<div class="search-common-panel">
<input type="text" x-webkit-speech="">
<i class="iconfont">ő</i>
</div>
</form>
</div>
</div>
<script>
//封装几个常用函数;
var getDOM = function(id){
return document.getElementById(id);
}
var addEvent = function(id,event,fn){
var el = getDOM(id)||document;
if(el.addEventListener){//非IE浏览器
el.addEventListener(event,fn,false);
}else if(el.attachEvent){//IE浏览器
el.attachEvent("on"+event,fn);
}
}
var tabSel="tab_1";
var setTab=function (tabSel){
getDOM('tab_2').className='';
getDOM('tab_1').className='';
if(getDOM(tabSel).className.indexOf("selected")<0){
getDOM(tabSel).className+=" selected";
}
}
addEvent("search-tab","mouseover",function(){
if(this.className.indexOf("trigger-hover")<0){
this.className+=" trigger-hover";
}
});
addEvent("search-tab","mouseout",function(){
setTab(tabSel);
getDOM('search-tab').className='search-list';
});
addEvent("tab_1","mouseover",function(){
setTab("tab_1");
});
addEvent("tab_1","mouseout",function(){
setTab(tabSel);
getDOM('search-tab').className='search-list';
});
addEvent("tab_1","click",function(){
tabSel="tab_1";
setTab(tabSel);
getDOM('search-tab').className='search-list';
});
addEvent("tab_2","mouseover",function(){
setTab("tab_2");
});
addEvent("tab_2","mouseout",function(){
setTab(tabSel);
getDOM('search-tab').className='search-list';
});
addEvent("tab_2","click",function(){
tabSel="tab_2";
setTab(tabSel);
getDOM('search-tab').className='search-list';
});
</script>
</body>
</html>
举报