<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="renderer" content="webkit"/> <meta name="force-rendering" content="webkit"/> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta http-equiv="Cache-Control" content="no-siteapp" /> <title>test mouse event</title> <style> body,html{ background:#777; } </style> </head> <body> document.querySelector(".ttt").click() -------------------- iiiiiiiiii mouseover mousedown <br/> <div class="ttt" style="background:red;" onclick="show()"> 8888888888 </div> <script> document.body.addEventListener("mouseover", function () { console.log("mouseover");}); document.body.addEventListener("mousedown", function () { console.log("mousedown");}); document.body.addEventListener("mouseenter", function () { console.log("mouseenter");}); document.body.addEventListener("click", function () { console.log("click");}); // 随意按下一个键盘按键 document.onkeydown = function(){ console.log('keydown') } document.onkeypress= function(){ console.log('onkeypress') } document.onkeyup = function(){ console.log('onkeyup') } // keydown onkeypress onkeyup function show(){ alert(000); } setInterval(function(){ //mouse over var event = document.createEvent("MouseEvents"); event.initEvent('mouseover', true, false); document.body.dispatchEvent(event); console.log('createEvent'); //click const event2 = document.createEvent('Events'); event2.initEvent( 'click', true, false ); document.body.dispatchEvent(event2); }, 3000); </script> </body> </html>
参考:https://www.cnblogs.com/h2285409/p/15989615.html标签:function,body,console,log,over,JS,document,mouse,click From: https://www.cnblogs.com/wgscd/p/17294998.html