87,839
社区成员




for (var i = 0; i < mA.length; i++) {
mA[i].onmouseenter = function(e){
console.log('1') ;
}
};
for (var i = 0; i < mA.length; i++) {
mA[i].onmouseleave = function(e){
console.log('2');
}
};
window.onload = function (){
var mDiv = document.getElementById('one'),
mA = mDiv.getElementsByTagName('a');
for (var i = 0; i < mA.length; i++) {
mA[i].onmouseover = function(e){
if(checkHover(e,this)){
console.log('1') ;
}
}
};
for (var i = 0; i < mA.length; i++) {
mA[i].onmouseout = function(e){
if(checkHover(e,this)){
console.log('2');
}
}
};
}
function checkHover(e, target) {
if (getEvent(e).type == "mouseover") {
return !contains(target, getEvent(e).relatedTarget
|| getEvent(e).fromElement)
&& !((getEvent(e).relatedTarget || getEvent(e).fromElement) === target);
} else {
return !contains(target, getEvent(e).relatedTarget
|| getEvent(e).toElement)
&& !((getEvent(e).relatedTarget || getEvent(e).toElement) === target);
}
}
function contains(parentNode, childNode) {
if (parentNode.contains) {
return parentNode != childNode && parentNode.contains(childNode);
} else {
return !!(parentNode.compareDocumentPosition(childNode) & 16);
}
}
//取得当前window对象的事件
function getEvent(e) {
return e || window.event;
}
参考:
http://blog.csdn.net/ltx851201/article/details/6800553
我这边试了可以解决,楼主试一试。