设为首页
收藏本站
最新电影
您现在的位置: 首页=>后台技术=>脚本特效=>其他 订阅本栏目  
为非IE浏览器添加mouseenter,mouseleave事件
时间: 2010-12-06 13:18:58 阅读次数:2122


先了解几个事件对象属性

target 指事件源对象,点击嵌套元素最里层的某元素,该元素就是target。IE6/7/8对应的是srcElement。

currentTarget 指添加事件handler的元素本身,如el.addEventListener中el就是currentTarget。IE6/7/8没有对应属性,可在handler内使用this来替代如evt.currentTarget = this。

relativeTarget 指事件相关的元素,一般用在mouseover,mouseout事件中。IE6/7/8中对应的是fromElement,toElement。

mouseentermouseleave 飞@飞Asp技术乐园IE9中仍然支持,另见 Greg Reimer 的博文 Goodbye mouseover, hello mouseenter飞飞Asp技术@乐园

mouseenter与mouseover区别在于:在元素内部移动时mouseenter不会触发。如下



<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" c/>
<title>mouseerter与mouseover区别(IE下测试)</title>
</head>
<body>
<div id="result" style="position:absolute;right:100px;top:5px;width:250px;height:400px;border:2px solid gray;overflow:auto;">
</div>
<h3>1,鼠标在div[id=parent1]内部移动时也会触发mouseover事件</h3>
<div id="parent1" style="width:400px;border:1px solid gray;padding:5px;">
<div id="child11" style="width:100px;height:100px;background:gold;float:left;">Child11</div>
<div id="child12" style="width:100px;height:100px;background:gold;float:right;">Child12</div>
<div style="clear:both;"></div>
</div>
<br/>
<h3>2,鼠标在div[id=parent2]内部移动时也不会触发mouseenter事件</h3>
<div id="parent2" style="width:400px;border:1px solid gray;padding:5px;">
<div id="child21" style="width:100px;height:100px;background:gold;float:left;">Child21</div>
<div id="child22" style="width:100px;height:100px;background:gold;float:right;">Child22</div>
<div style="clear:both;"></div>
</div>
<script type="text/javascript">
function on(el,type,fn){
el.addEventListener ? el.addEventListener(type, fn, false) : el.attachEvent('on' + type, fn);
}
function $(id){
return document.getElementById(id);
}
var p1 = $('parent1'),
p2 = $('parent2');
function fn(e){
var d = document.createElement('div');
d.innerHTML = e.type;
$('result').appendChild(d);
}
on(p1,'mouseover',fn);
on(p2,'mouseenter',fn);
</script>
<body>
</html>






站内搜索    

下一篇jquery的live绑定多个事件/hover的方法

上一篇用键盘打开网页代码

本栏目最新 栏目最新列表
xhEditor v1.1.7 发布,国产开源XHTML在线编
收集的一些轻量级非常实用的前端开发小工具
javascript中cookie的设置,读取,删除
jquery插件:飞飞表情插件v1.0_[普通表情/魔
Jquery插件:textarea使用“autoresize”自
网站优化策划 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新 站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息  
MIME介绍 及 [1] [2] [3]
巧用Google和迅雷来下载
VIA Rhine II Fast Ethe
Transact SQL 常 [1] [2]
电脑常用端 [1] [2] [3]
十道羊皮卷 欣赏+mp3版+
Do you get a kick out
每日一句:A friend and
每日一句:Theres no tu
网站开发常用手册
相关文章
“模拟mouseenter和
为非IE浏览器添加mo
jquery的live绑定多
 
 width= 
伟哥博客 西安房产 123最新电影 三四六四