x
 
<!DOCTYPE html>
<html>
<body>
<style>
div {
  padding:50px;
  background-color: Tomato;
  color: white;
}
</style>
<script>
function myFunction(event) {
var x = document.createEvent("MouseEvent");
x.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.getElementById("myDiv").dispatchEvent(x);
}
</script>
<h1>createEvent() 方法</h1>
<p>createEvent() 方法允许您模拟任何事件。</p>
<p>在本例中,每次将鼠标悬停在红色 div 上时,它都会获得一个新星:</p>
<div onmouseover="this.innerHTML += '*';" id="myDiv">*</div>
<br>
<button onclick="myFunction(event)">模拟鼠标悬停</button>
</body>
</html>