mousedown mouseup click 触发顺序

时间:2022-10-10 10:15:45

mousedown、mouseup、click执行顺序是从左到右的,更重要的是一旦mousedown事件激活,正常情况下后面两个事件也肯定会被激活
mousemove 事件在是一直在元素上运行的(如果加上的话)
 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
  5. <title>mousedown mouseup click触发顺序</title>
  6. </head>
  7. <body>
  8. <div id="div1"
  9. onmousedown="mouseDownFun();"
  10. onmouseup="mouseUpFun();"
  11. onclick="clickFun();"
  12. style="background:#CCC; border:3px solid #999; width:200px; height:200px; padding:10px;overflow-y: scroll"></div>
  13. <input style="margin-top:10px" type="button" onclick="document.getElementById('div1').innerHTML='';" value="清除信息"/>
  14. <script type="text/javascript">
  15. var div1 = document.getElementById('div1');
  16. function mouseDownFun() {
  17. div1.innerHTML += Math.random() + '<br/>';
  18. div1.innerHTML += 'mouseDown<br/>';
  19. }
  20. function mouseUpFun() {
  21. div1.innerHTML += 'mouseUp<br/>';
  22. }
  23. function clickFun() {
  24. div1.innerHTML += 'click<br/>';
  25. div1.scrollTop = div1.scrollHeight; //滚动到底部
  26. }
  27. </script>
  28. </body>
  29. </html>

mousedown mouseup click 触发顺序