The mouse events in js mainly include onclick, onmousedown, onmouseup, oncontextmenu, and ondblclick. All these events contain an event object event. Of course, in lower versions of IE, the event object is hung under the window. We will discuss this separately.
1. Add events through html
<input type="button" click="alert(1)"/>
2. Add events through DOM0 level Event
<input type="button" value="点击"/> <script>var btn=document.getElementsByTagName('input')[0]; btn.onclick=function(){ alert(1); }</script>
3. Add event
# through DOM2 level method ## Event monitoring mainly accepts three parameters, event type, function that needs to be executed, and whether to bubble. By default, bubbling is allowed.
document.addEventListener('click',function( ){ },true)
* When the onclick event is triggered, console.log(ev.which), the which value of the left mouse button is 1
* When the oncontextmenue is triggered, The value of the right button of the mouse is 3 and the onclick event will not be triggered
* When mousewheel is used, the value of the middle button of the mouse is 0
* When document.down is used, the mouse button can be moved from left to right according to the different keys. The values are 1, 2, 3
* Under chrome, check ev.wheelDelta, up is 120, down is -120
* Under FirFox, add a wheel event to the mouse through addEventListenner(), event The type is DOMMouseScroll, and the view is using ev.detail
* Up is 3, down is -3
*
The above is the detailed content of Summary of mouse events in js. For more information, please follow other related articles on the PHP Chinese website!