1.在IE中使用event对象
event对象作为window对象的属性提供。利用event对象的srcElement属性(在Mozzilla浏览器中是target属性)
引用事件的元素.
2.在Mozzilla 浏览器中使用event对象
function imgClick(evt){
alert(evt.target.src);
}
<img src="1.jpg" onClick="imgClick(event)"/>
event对象作为window对象的属性提供。利用event对象的srcElement属性(在Mozzilla浏览器中是target属性)
引用事件的元素.
2.在Mozzilla 浏览器中使用event对象
function imgClick(evt){
alert(evt.target.src);
}
<img src="1.jpg" onClick="imgClick(event)"/>
event对象的属性
| ||
属性描述
|
IE
|
Mozzilla
|
触发事件的元素 | srcElement | target |
事件类型 | type | type |
元素的X坐标 | offsetX | |
元素的Y坐标 | offsetY | |
定位元素的X坐标 | x | layerX |
定位元素的Y坐标 | y | layerY |
窗口的X坐标 | clientX | clientX |
窗口的Y坐标 | clientY | clientY |
屏幕的X坐标 | screenX | screenX |
屏幕的Y坐标 | screenY | screenY |
鼠标按键 | button | button |
键盘按键 | keyCode | keyCode |
按下shift键 | shiftKey | shiftKey |
按下alt键 | altKey | altKey |
按下ctrl键 | ctrlKey | ctrlKey |
上一级元素 | fromElement | relatedTarget |
下一级元素 | toElement | relatedTarget |