html dom文件的事件对象? [英] Documentation of html dom Event object?
问题描述
任何人都可以指向html 事件
对象的文档?
Bonus Reading
我知道全局事件
对象存在的唯一原因是因为提到在一个Stackoverflow答案:
onclick =SomeEvent(this,event)
函数SomeEvent(el,event){
var target = event.srcElement || event.target;
if(el === target){
//运行代码
}
}
似乎有这些属性:
-
srcElement
-
目标
Google搜索我发现W3学校的页面在 HTML DOM事件对象,其中列出了以下属性:
-
bubbles
:返回事件是否是冒泡事件 -
cancelable
:返回事件是否可以进行默认操作阻止 -
currentTarget
:返回事件侦听器触发事件的元素 -
eventPhase
:返回事件流当前正在评估的阶段 -
目标
返回元素触发事件 -
timeStamp
返回创建事件的时间(相对于时期的毫秒) -类型
返回事件的名称
和方法:
-
initEvent()
:指定事件类型,不管事件是否可以浮动,不管事件的默认操作可以防止 -
preventDefault()
:如果可以取消该事件,则意味着实施通常采用的任何默认操作作为事件的结果将不会发生 -
stopPropagation()
:为了防止在事件流中进一步传播事件
缺少 srcElement
,所以说这不是完整的文档是安全的。 >
然后有微软的事件对象中的ferrer>页面。它没有任何文件;只提到对象。但是它确实提到:
某些属性在某些事件期间可能没有有意义的值。例如,
fromElement
和toElement
属性
W3Schools页面没有提到 fromElement
或 toElement
properties;所以它不完整。
MSDN页面引用了一个链接到W3C:
标准信息
文件对象模型(DOM)2级HTML规范,第1.6.5节
搜索页面没有提到 fromElement
或 toElement
。
所以任何人都可以指向html 事件
对象的文档?
MDN网站提供非常可靠的信息: https://developer.mozilla.org/en/ DOM /事件。您的 event.toElement
属性是一个非标准的Microsoft事情,一个快速测试显示Firefox中的属性 undefined
< body onclick =alert(event.srcElement)>点击
正确的属性是 target
。还要注意,事件
是不是全局,它只是一个局部变量。建议您使用 addEventListener
添加DOM事件,如MDN页面所述。
quirksmode.org 在浏览器之间的兼容性方面有不错的表。
W3schools ...好 http://w3fools.com
由于您想了解有关IE特定的 srcElement
属性的更多信息,请查阅Microsofts documention。从 srcElement属性:
获取事件最初分派到的元素。与目标进行比较。
注释
注意srcElement属性用于向后兼容。使用目标属性。
Can anyone point me to the documentation of the html Event
object?
Bonus Reading
The only reason i know a global Event
object exists is because it was mentioned in a Stackoverflow answer:
onclick="SomeEvent(this, event)"
function SomeEvent( el, event ) {
var target = event.srcElement || event.target;
if( el === target ) {
// run your code
}
}
Where it seems to have the properties:
srcElement
target
Googling around i found W3 School's page on the HTML DOM Event object, which lists the following properties:
bubbles
: Returns whether or not an event is a bubbling eventcancelable
: Returns whether or not an event can have its default action preventedcurrentTarget
: Returns the element whose event listeners triggered the eventeventPhase
: Returns which phase of the event flow is currently being evaluatedtarget
Returns the element that triggered the eventtimeStamp
Returns the time (in milliseconds relative to the epoch) at which the event was created -type
Returns the name of the event
and methods:
initEvent()
: Specifies the event type, whether or not the event can bubble, whether or not the event's default action can be preventedpreventDefault()
: To cancel the event if it is cancelable, meaning that any default action normally taken by the implementation as a result of the event will not occurstopPropagation()
: To prevent further propagation of an event during event flow
It's missing srcElement
, so it's safe to say it's not complete documentation.
Then there's Microsoft's page on the event
object. It doesn't have any documentation; only mentioning the object. But it does mention that:
some properties might not have meaningful values during some events. For example, the
fromElement
andtoElement
properties
W3Schools page doesn't mention fromElement
or toElement
properties; so it's not complete.
The MSDN page references a link to W3C:
Standards information
Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
A search of that page contains no mention of fromElement
or toElement
.
So can anyone point me to documentation of the html Event
object?
The MDN site provides very reliable information: https://developer.mozilla.org/en/DOM/event. Your event.toElement
property is a non-standard Microsoft thing, a quick test showed undefined
for the property in Firefox:
<body onclick="alert(event.srcElement)">Click
The correct property to use is target
. Also note that event
is not global, it is only a local variable. You are suggested to use addEventListener
for adding DOM events as described in the MDN page.
quirksmode.org has nice tables on compatibility across browsers.
W3schools... well http://w3fools.com
Since you want to know more about the IE-specific srcElement
property, consult Microsofts documention. From srcElement property:
Gets the element that the event was originally dispatched to. Compare to target.
Remarks
Note The srcElement property is provided for backward compatibility. Use the target property instead.
这篇关于html dom文件的事件对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!