当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > event.currentTarget和document.activeElement用法

CSS样式表
css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法
CSS解决链接锚点定位偏移的代码
一个css transform效果 很有图片的感觉
ie6,ie7,firefox的textarea滚动条、边框
12种CSS BUG解决方法与技巧
CSS 常用设置备忘
table中td内容换行问题
外部引用CSS中 link与@import的区别
CSS background-position 属性 定位图片
css 解决英文字符与阿位伯数字自动换行
div ,frame等空间的透明实现代码
CSS中几种浏览器对不同版本的支持与区分写法
多个浏览器对容器宽度实际像素的解释
CSS 用ul li做圆角表格
CSS 之dl dt dd模拟表格实例代码
创建超链接及css 样式设置
页面位置 top、postop、scrolltop、offsetTop、scrollHeight、offsetHeight、clientHe
css float 解析学习
学习DIV+CSS难不难 需要掌握哪些知识
IE8 CSS hack

CSS样式表 中的 event.currentTarget和document.activeElement用法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 187 ::
收藏到网摘: n/a


firefox 的 event.currentTarget 和 ie 的 document.activeElement 这两个完全含义不一致的对象却被捆绑在一起做成了浏览器兼容代码。 大家在google搜索的时候 都会发现 document.activeElement || event.currentTarget 的用法。
其实这样的用法是错误的,因为这两个属性的意义都不一样。
event.currentTarget
Identifies the current target for the event, as the event traverses the DOM.
识别当前事件触发的dom
document.activeElement
Gets the object that has the focus when the parent document has focus.
获得当前focus的对象
例子 <script type="text/javascript">
var show = function (e) {
alert(e.currentTarget?"获取到了 currentTarget":"获取到了 document.activeElement")
alert((e.currentTarget || document.activeElement).tagName);
};
</script><BR> 案例1: <br/><BR> <a href="#"><img src="http://www.google.cn/images/nav_logo3.png" border="0" alt="" onclick="show(event)"/></a> <br/> <br/><BR> 案例2: <br/><BR> <a href="#" onclick="show(event)"><img src="http://www.google.cn/images/nav_logo3.png" border="0" alt=""/></a> <br/><P></P>
<P> 这两个案例,在ie和firefox下试验一下。</P>
最后测试补充:后来测试了一下 document.activeElement 的支持程度,发现四大浏览器safari除外, ie firefoxopera都提供了这个对象的支持。但是有点需要注意的,上面的例子中 opera 会把图片作为 可以 focus的对象。导致document.activeElement的结果不一致...