//阻止浏览器默认的事件冒泡事件 function stopBubble(e){ //非IE浏览器 if(e && e.stopPropagation){ e.stopPropagation(); } //IE浏览器 else{ window.event.cancelBubble = true; } }
var li = document.getElementsByTagName("li"); for(var i=0;i<li.length;i++){ li[i].onmouseover = function(e){ this.style.border = '1px solid #f00'; stopBubble(e); } li[i].onmouseout = function(e){ this.style.border= '0px'; stopBubble(e); } }