运行 ❯
获取您
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Document Object</h1> <h2>The createEvent() Method</h2> <p>The createEvent() method allows you to simulate events.</p> <p>"myDiv" will get a new star every time you mouse over it:</p> <div id="myDiv" style="padding:50px;background-color:yellow;" onmouseover="this.innerHTML += '*';">*</div> <p><button onclick="myFunction(event)">Simulate Mouse Over</button></p> <script> function myFunction(event) { const ev = document.createEvent("MouseEvent"); ev.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); document.getElementById("myDiv").dispatchEvent(ev); } </script> </body> </html>