在最近写js的时候,发现了一个代码的兼容性有些问题(ie能跑,火狐不行),心中还在疑惑怎么会这样,不是jquery的跨浏览器兼容做得很好的么,后来查阅官方文档之后才知道是我的使用有问题,记录一下,供自己和各位参考。
1.问题原因
问题出现的原因是我在代码中使用了event的srcElement这个属性,这个属性在ie中有,但是在FF中就没有(目前没验证其他的浏览器),所以代码在ie中能够正常,ff中却出现了问题。
2.jquery中event的标准属性
在查阅了jquery的官方文档之后官方文档,知道jquery只将以下六个属性作为能够跨浏览器的属性,官方的描述日下:
2.1target
The DOM element that initiated the event.
The target
property can be the element that registered for the event or a descendant of it. It is often useful to compare event.target
to this
in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.
2.2relatedTarget
The other DOM element involved in the event, if any.
For mouseout
, indicates the element being entered; for mouseover
, indicates the element being exited.
2.3pageX
The mouse position relative to the left edge of the document.
2.4pageY
The mouse position relative to the top edge of the document.
2.5which
For key or mouse events, this property indicates the specific key or button that was pressed.
2.6metaKey
Returns a boolean value (true
or false
) that indicates whether or not the META key was pressed at the time the event fired. This key might map to an alternative key name on some platforms.