如果同时设置了点击事件和移出事件,怎样做到点击事件完成后,就不再执行移出事件了呢????(常理是:点击完成后肯定是要移出的,那么就会触发移出事件,如何阻止移出事件的执行啊,求解答!)
如果同时设置了点击事件和移出事件,怎样做到点击事件完成后,就不再执行移出事件了呢????(常理是:点击完成后肯定是要移出的,那么就会触发移出事件,如何阻止移出事件的执行啊,求解答!)
如果同时设置了点击事件和移出事件,怎样做到点击事件完成后,就不再执行移出事件了呢????(常理是:点击完成后肯定是要移出的,那么就会触发移出事件,如何阻止移出事件的执行啊,求解答!)
2018-01-08
上面的有点小问题
只有选择栏的代码,可以实现
<!doctype html>
<html>
<head>
<!--在IE浏览器的最新版本下进行渲染-->
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>淘宝选择栏</title>
<style type="text/css">
body{font: 12px/1.5 tahoma,arial,sans-serif;}
.searchbox{position:absolute;top:200px;left:300px;}
.search-choose{float:left;position:relative;left:1px;width:55px;height:41px;overflow:hidden;background:#FFF;border-left:1px solid #F6F6F6;border-right:1px solid #e5e5e5;}
ul{list-style:none;display:block;}
ul,li{margin:0;padding:0}
.search-choose li{display:block;height:41px;line-height:41px;overflow:hidden;text-align:center;}
.search-choose li a{text-decoration: none;color:#6c6c6c;}
.search-choose .search-selected{background:#f6f6f6;display:block;}
.trigger-hover{height:auto;}
.trigger-hover li{display:block;}
</style>
</head>
<body>
<div class='searchbox'>
<div class='search-choose' id='search_choose'>
<ul>
<li id='search_1' class='search-selected'><a href='#'>宝贝</a></li>
<li id='search_2'><a href='#'>店铺</a></li>
</ul>
</div>
</div>
<!--搜索框模块-->
<!--※2搜索引擎选择模块-->
<script>
var flag1=true,flag=true;
var getDOM=function(id){
return document.getElementById(id);
}
var addEvent=function(id,event,fn){
var el=getDOM(id);
if(el.addEventListener){
el.addEventListener(event,fn,false);
}else if(el.attachEvent){
el.attachEvent('on'+event,fn);
}
}
addEvent('search_choose','mouseover',function(){
if(flag1){
this.className +=' trigger-hover';
}
flag1 = true;
});
addEvent('search_choose','mouseout',function(){
this.className ='search-choose';
});
addEvent('search_1','mouseover',function(){
if(this.className.indexOf('search-selected')<0){
this.className +=' search-selected';
getDOM('search_2').className='';
}flag = true;
});
addEvent('search_1','mouseout',function(){
if(flag){
this.className ='';
}
});
addEvent('search_1','click',function(){
getDOM('search_choose').className = 'search-choose';
flag1 = false;
flag = false;
});
addEvent('search_2','mouseover',function(){
if(this.className.indexOf('search-selected')<0){
this.className +=' search-selected';
getDOM('search_1').className='';
}
flag = true;
});
addEvent('search_2','mouseout',function(){
if(flag){
this.className ='';
}
});
addEvent('search_2','click',function(){
var tab = getDOM('search_1').innerHTML;
getDOM('search_1').innerHTML=getDOM('search_2').innerHTML;
getDOM('search_2').innerHTML = tab;
getDOM('search_choose').className = 'search-choose';
flag = false;
});
</script>
</body>
</html>
复制直接拿过去就能用
这是自己改的源码 老师的代码有冲突。。。。自己看看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>淘宝搜索框</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.ttf) format("truetype"),
url( http://g.tbcdn.cn/tb/icon-font/1.1.5/iconfont.svg#uxiconfont) format("svg");}<!--字体图标文件-->
body{font: 12px/1.5 tahoma,arial,sans-serif;}
a{text-decoration: none;}
.search-tips{float: right;margin: 3px 0 0 15px;}
.search-tips a{color: #6c6c6c;}
.search-button{float: right;}
.btn-search{background-image:url(http://gtms01.alicdn.com/tps/i1/T1qyj8Fc8aXXc4E9bI-400-300.png);
width: 100px;
height: 45px;
background-position: 0 -200px;
border: 0;
cursor: pointer;
}
.search-common-pannel{
height: 39px;
background-color: #f50;
padding: 3px 0 3px 77px;
overflow: hidden;
}
.search-common-pannel input{
height: 39px;
line-height: 39px;
width: 100%;
border: 0 none;
outline: 0;
background-color: #fff;
}
.search-container{position: relative;}
.search-common-pannel 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;
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 ;
}
.search-list li{
display:block;
height: 39px;
line-height: 39px;
text-align: center;
overflow: hidden;
}
.search-list li a{color: #6c6c6c;}
.search-list.selected{background: #333333;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="">
<a href="#">宝贝</a>
</li>
<li id="tab_2" class="">
<a href="#">店铺</a>
</li>
</ul>
</div>
<div class="search-pannel">
<form class="">
<div class="search-tips">
<a>高级<br>搜索</a>
</div>
<div class="search-button">
<button type="submit" class="btn-search"></button>
</div>
<div class="search-common-pannel">
<input type="text" x-webkit-speech=""/>
<i class="iconfont">ő</i>
</div>
</form>
</div>
</div>
</body>
<script>
var flag1 ;
var flag2 ;
var getDOM=function(id){
return document.getElementById(id);
}
var addEvent=function(id,event,fn){
var el=getDOM(id);
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('search-tab','mouseout',function(){
this.className ='search-list';
});
addEvent('tab_1','mouseover',function(){
if(this.className.indexOf('selected')<0){
this.className +=' selected';
getDOM('tab_2').className='';
flag1 = true;
}
});
addEvent('tab_1','mouseout',function(){
if(flag1){
this.className ='';
}
});
addEvent('tab_2','mouseover',function(){
if(this.className.indexOf('selected')<0){
this.className +=' selected';
getDOM('tab_1').className='';
flag2 = true;
}
});
addEvent('tab_2','mouseout',function(){
if(flag2){
this.className ='';
}
});
addEvent('tab_1','click',function(){
getDOM('search-tab').className = 'search-list';
flag1 = false;
});
addEvent('tab_2','click',function(){
var tab = getDOM('tab_1').innerHTML;
getDOM('tab_1').innerHTML=getDOM('tab_2').innerHTML;
getDOM('tab_2').innerHTML = tab;
getDOM('search-tab').className = 'search-list';
flag2 = false;
});
</script>
<!--每点击一次,都会出发onmouseout事件,
所以要设计一个标记来表示是否是出发了点击事件,
如果是,那么onmouseout将不会清除样式-->
</html>
举报