jQuery中的事件处理(事件对象)
1.打印对象属性:
代码:
<script type="text/javascript"> //入口函数 $(document).ready(function(e){ $("button").bind("click",function(e){ console.log(e) }) }) </script>
输出:
k.Event {originalEvent: MouseEvent, type: "click", target: button, currentTarget: button, isDefaultPrevented: ƒ, …}
altKey: (...) //是否点击
bubbles: (...)
cancelable: (...)
changedTouches: (...)
ctrlKey: (...)
detail: (...)
eventPhase: (...)
metaKey: (...)
pageX: (...) //位置
pageY: (...) //位置
shiftKey: (...)
view: (...)
char: (...)
code: (...)
charCode: (...)
key: (...)
keyCode: (...)
button: (...)
buttons: (...)
clientX: (...)
clientY: (...)
offsetX: (...)
offsetY: (...)
pointerId: (...)
pointerType: (...)
screenX: (...)
screenY: (...)
targetTouches: (...)
toElement: (...)
touches: (...)
which: (...)
originalEvent: MouseEvent {isTrusted: true, screenX: 931, screenY: 215, clientX: 81, clientY: 18, …}
type: "click" // 事件类型
isDefaultPrevented: ƒ Se()
target: button
currentTarget: button //触发当前事件的DOM元素
relatedTarget: null //返回与事件相关的节点
timeStamp: 1961.6650000098161
jQuery341047216147197495384: true
delegateTarget: button
handleObj: {type: "click", origType: "click", data: null, guid: 1, handler: ƒ, …}
data: null
__proto__: Object