这是我现在用的
/ * * * * * * * * html * * * * * * * * * /
<form >
<span>
<a href="#" id="search_tab">商品
<i class="icon_1"></i>
</a>
<span id="search_list" class="search_list">
<a href="#" id="search_tab1">商品</a>
<a href="#" id="search_tab2">店铺</a>
</span>
</span>
<span>
/ * * * * * * * * js * * * * * * * * * /
addEvent('search_tab1','mouseover',function(){
this.className ='selected';
})
addEvent('search_tab1','mouseout',function(){
this.className ='';
})
addEvent('search_tab2','mouseover',function(){
this.className ='selected';
})
addEvent('search_tab2','mouseout',function(){
this.className ='';
})
这是我按照课程里的写的。为什么这个就不行了呢?
“鼠标第一次移上还有,可第二次移上就没有了。”
/ * * * * * * * * html * * * * * * * * * /
<form >
<span>
<a href="#" id="search_tab">商品
<i class="icon_1"></i>
</a>
<span id="search_list" class="search_list">
<a href="#" id="search_tab1" class="selected">商品</a>
<a href="#" id="search_tab2">店铺</a>
</span>
</span>
<span>
<input type="text" required="required" class="search_input" placeholder="请输入关键词、学校名等...">
<input type="submit" value="搜索">
</span>
</form>
/ * * * * * * * * js * * * * * * * * * /
// JavaScript Document
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','click',function(){
getDOM('search_tab').style.display ="none";
getDOM('search_list').className = 'search_list_pop';
})
addEvent('search_tab1','mouseover',function(){
if(this.className.indexof('selected')<0){
this.className+='selected';
}
})
addEvent('search_tab1','mouseout',function(){
this.className ='';
})
addEvent('search_tab2','mouseover',function(){
if(this.className.indexof('selected')<0){
this.className+='selected';
}
})
addEvent('search_tab2','mouseout',function(){
this.className ='';
})
第一张 图
第二张 图
一瞬儿光
慕的地6079101
路人丶丨
再见陌生人123
一杯2块的奶茶
相关分类