默默模式
2016-01-07 01:14
function bind(el,eventType,callback){
if(typeof el.addEventListener === 'function'){
el.addEventListener(el,eventType,callback, false);
}else if(typeof el.attechEvent === 'function'){
el.attachEvent('on' + eventType, callback);
}
}
function mouseoverHandler(e){
var target = e.target || e.srcElement;
var outer = document.getElementById('subject');
var list = outer.getElementsByTagName('li');
for(var i = 0; i < list.length; i++){
list[i].className = '';
}
while(target.tagName != 'LI' || target.tagName == 'BODY'){
target = target.parentNode;
}
target.className = 'big';
}
function initList(){
var outer = document.getElementById('subject');
var list = outer.getElementsByTagName('li');
for(var i =0;i < list.length; i++){
bind(list[i],'mouseover', mouseoverHandler);
}
}
initList();
报错了 你的很多分号写的是中文输入法的
function bind(el,eventType,callback){ if(typeof el.addEventListener === 'function'){ //这行多写一个 el el.addEventListener(eventType,callback, false); }else if(typeof el.attechEvent === 'function'){ el.attachEvent('on' + eventType, callback); } } function mouseoverHandler(e){ var target = e.target || e.srcElement; var outer = document.getElementById('subject'); //这行的;是中文的 var list = outer.getElementsByTagName('li'); for(var i = 0; i < list.length; i++){ list[i].className = ''; } while(target.tagName != 'LI' || target.tagName == 'BODY'){ target = target.parentNode; } target.className = 'big'; } function initList(){ var outer = document.getElementById('subject'); //这行的;是中文的 var list = outer.getElementsByTagName('li'); for(var i =0;i < list.length; i++){ bind(list[i],'mouseover', mouseoverHandler); } } initList();
看注释,一共3个错误
手风琴效果
40811 学习 · 111 问题
相似问题