Javascript 在元素上移动鼠标的DOM方法是什么?

Javascript 在元素上移动鼠标的DOM方法是什么?,javascript,dom,Javascript,Dom,我的问题很简单,我想自动化一个过程,首先我需要将鼠标悬停在一个特定的元素上,然后单击第二个元素,它将在鼠标悬停后替换第一个元素。那么,使用什么dom方法使鼠标指针悬停在带有纯javascript的第一个元素上呢?我想您可以使用javascript鼠标悬停事件。也许有一些你想要使用的示例代码 <p id="p" class="p" onmouseover="changElement()">Sample Code</p&g

我的问题很简单,我想自动化一个过程,首先我需要将鼠标悬停在一个特定的元素上,然后单击第二个元素,它将在鼠标悬停后替换第一个元素。那么,使用什么dom方法使鼠标指针悬停在带有纯javascript的第一个元素上呢?

我想您可以使用javascript鼠标悬停事件。也许有一些你想要使用的示例代码

<p id="p" class="p" onmouseover="changElement()">Sample Code</p>
<script>
var el = document.querySelector('p');

function changeElement(){
var newEl = document.createElement('p');
newEl.innerHTML = '<b>Hello World!</b>';
el.parentNode.replaceChild(newEl, el);
}

</script>
示例代码

var el=document.querySelector('p'); 函数changelement(){ var newEl=document.createElement('p'); newEl.innerHTML='Hello World!'; el.parentNode.replaceChild(newEl,el); }
你不能用javascript移动鼠标。但是,您可以使用对象触发悬停事件。@WaisKamal“eventTarget.dispatchEvent(new MouseEvent(MouseEvent.MOUSEOVER))”,这与您的意思接近吗?有点接近,是的。