代码示例:(标识:jsck_event_createevent)
<!DOCTYPE html>
<html>
<body>
<h1>Document 对象</h1>

<h2>createEvent() 方法</h2>

<p>createEvent() 方法允许您模拟事件。</p>

<p>每当您将鼠标在其上悬停时,"myDiv" 会获得一个新的星星:</p>

<div id="myDiv"
style="padding:50px;background-color:yellow;"
onmouseover="this.innerHTML += '*';">*</div>

<p><button onclick="myFunction(event)">模拟鼠标悬停</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>
运行结果: