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

为什么我的代码实现不了点击切换的功能,求指点

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8" />

<title>taobao demo</title>

<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.tff) format("truetype"),

   url(http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.svg#uxiconfont) format("svg");

}

body{font-size: 12px/1.5 tahoma,arial,sans-serif; }

a{text-decoration: none;}

.search-tips{float: right;padding: 3px 0 0 15px;}

.search-tips{color: #6c6c6c;}

.search-button{float: right;}

.btn-search{background-color: #F90;color:#FFF;width: 100px;height: 45px;border: 0;cursor: pointer;font-size: 18px;}

.search-common-panel{height: 39px;background-color: #f50;overflow: hidden;padding: 3px 0 3px 77px;}

.search-common-panel input{height: 37px;line-height: 37px;width: 100%;border: 0 none;outline: 0;background-color: #FFF;}

.iconfont{font-family: iconfont;font-size: 12px;font-style: normal;}

.search-container{position: relative;}

.search-common-panel i{position: absolute;top: 14px;left: 86px;z-index: 2;color: #ccc;}

ul{list-style: none;display: block;}

ul,li{margin: 0;padding: 0;}

.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;text-align: center;}

.search-list li{display: none;height: 39px;line-height: 39px;overflow: hidden;}

.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 id="search_tab" class="search-list">

<ul>

<li id="tab_1" class="selected "><a href="#">宝贝</a></li>

<li id="tab_2"><a href="#">店铺</a></li>

</ul>

</div>

<div class="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" name="" x-webkit-speech="">

<i class="iconfont">ő</i>

</div>

</form>

</div>

</div>

</body>

<script>

var getDOM = function (id) {

return document.getElementById(id);

}


var addEvent = function(id,event,fn){

var el = getDOM(id)||document;

if(el.addEventListener){

el.addEventListener(event,fn,false);

}else if(el.attachEvent){

el.attachEvent('on'+event,fn);

}

}


addEvent('search_tab','mouseover',function () {

this.className+=' trigger-hover';});


addEvent('tab_1','mouseover',function () {

if(this.className.indexOf('selected')<0){

this.className+=' selected';}

});


addEvent('tab_1','mouseout',function () {

this.className='';

});


addEvent('tab_1','click',function () {

getDOM('search_tab').className='search-list';

});


addEvent('tab_2','mouseover',function () {

if(this.className.indexOf('selected')<0){

this.className+=' selected';}

});


addEvent('tab_2','mouseout',function () {

this.className='';

});



addEvent('tab_2','click',function () {

getDOM('search_tab').className='search-list';

});

</script>

</html>


正在回答

举报

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

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

进入课程

为什么我的代码实现不了点击切换的功能,求指点

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信