onmouseleave火狐firefox
原载于:原文章%77w%77%2Ef%6F%72%61%73%70%2E%63n
在javascript中,Ie支持onmouseleave,但是firefox中没有onmouseleave。怎么才能在火狐浏览器下使用onmouseleave呢,在蓝
色理想上有人写了个代码,现在转载到本站
原站地址:http://bbs.blueidea.com/thread-2964821-1-8.html
代码如下:
var $ext = function(t,f){for(var p in f){t[p]=f[p]} return t};
var IE = '\v' == 'v';
var contains = function(wrap,child){
if(IE) return wrap.contains(child);
while(child && typeof(child.parentNode) != "undefind"){
if(wrap == child) return true;
child = child.parentNode;
}
return false;
};
$.prototype = {//给获取对象函数附加方法mouseleave
mouseleave : function(fn){
if(IE){
this.attachEvent('onmouseleave',fn);
}else{
this.addEventListener('mouseout',function(e){
tar = e.relatedTarget;
if(!contains(this, tar)){
fn.call(this);
}
}, false);
}
return this;
}
};
var $ = function(o){//这里是获取对象
var _o = typeof o =="string" ? document.getElementById(o) : o;
return this == window ? new $(_o):$ext(_o, $.prototype);
};
$('outter').mouseleave(function(){alert('鼠标已经离开了')})
该楼主是js还是相当不错的。再此转载。
<网f站o学a习s制p作.cn>