html – 如何在IE9中访问Event.target?
发布时间:2020-12-14 19:30:42 所属栏目:资源 来源:网络整理
导读:HTML DOM对象模型定义了一个Event对象 with a target property. 看MSDN,Microsoft记录了 target property.他们还将 srcElement 作为Internet Explorer早期版本的目标别名: The target property is similar to 07003 in Windows Internet Explorer 8 and ear
HTML DOM对象模型定义了一个Event对象
with a
target property.
看MSDN,Microsoft记录了
所以在这里我在Internet Explorer中,坐在一个点击断点: <div class="day" onclick="divClick(this)"> function divClick(sender) { var divCell = sender; 在F12工具控制台,我可以要求全球事件对象: >> event { actionURL : "",altKey : false,altLeft : false,behaviorCookie : 0,behaviorPart : 0,bookmarks : null,boundElements : {...},button : 0,buttonID : 0,cancelBubble : false ... } 我可以请求event.srcElement对象: >> event.srcElement { align : "",noWrap : false,dataFld : "",dataFormatAs : "",dataSrc : "",currentStyle : {...},runtimeStyle : {...},accessKey : "",className : "header",contentEditable : "inherit" ... } 但是event.target为空: >> event.target 如果我看事件,没有目标属性: 那么如何在Internet Explorer中访问事件对象的目标属性(9(文档模式:IE9标准(浏览器模式:IE9)))? 解决方法
如果要在IE9中使用event.target,则需要使用addEventListener() – 方法为该元素分配事件处理程序.
<div id="day" class="day"></div> document.getElementById('day').addEventListener('click',divClick,false); function divClick(e){ alert(e.target); divCell=this; : } 在divClick()中,您可以使用关键字this来引用日期.参数e包含对事件对象本身的引用. BTW,在MSDN中,您可以找到更适合于Web development而不是Windows开发的IE文档. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |