抄的Mark老师的JavaScript代码,代码一模一样,没有效果。下载老师的源文件,然后复制了里面的jQuery代码,也没有改动任何东西,但是有效果,,这是为什么,求指教。
老师的JavaScript代码:
function bind(el, eventType, callback){
if(typeof el.addEventListener === 'function'){
el.addEventListener(el, eventType, callback, false);
}else if(typeof el.attachEvent === 'function'){
el.attachEvent('on'+eventType, callback);
}
}
function mouseoverHandler(e){
var target=e.target ||e.srcElement;
var outer=document.getElementById("subject");
var list=outer.getElementByTagName("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.getElementByTagName("li");
for (var i=0; i< list.length; i++){
bind(list[i],'mouseover',mouseoverHandler);
}
}
initList();
老师的jQuery代码:
<script type="text/javascript">
function mouseover(e){
var list = $('#subject li');
var target = $(e.target).parents('li');
list.removeClass('big');
target.addClass('big');
}
(function(){
var outer = $('#subject');
outer.find('li').on('mouseover', mouseover);
})()
</script>