在JavaScript中以编程方式触发onmouseover事件 [英] Trigger onmouseover event programmatically in JavaScript
本文介绍了在JavaScript中以编程方式触发onmouseover事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在纯JavaScript中以编程方式触发 onmouseover
事件?或者从 onmouseover
事件中提取该方法直接调用它?
Is there a way to programmatically trigger the onmouseover
event in plain JavaScript? or "extract" the method from the onmouseover
event to call it directly?
例如
<div id="bottom-div" onmouseover="myFunction('some param specific to bottom-div');">
<div id="top-div" onmouseover="????????"></div>
</div>
top-div高于bottom-div,所以 onmouseover
不会在bottom-div中被触发。我需要一种方法来调用 myFunction('某些param特定于bottom-div');
来自top-div
top-div is above bottom-div, so the onmouseover
won't get fired in bottom-div. i need a way of calling myFunction('some param specific to bottom-div');
from top-div
推荐答案
你会这样做:
document.getElementById('top-div').onmouseover();
但是,正如评论中所提到的,在被视为问题之前,它值得测试。
However, as mentioned in the comments, it would be worth testing before being considered an issue.
这篇关于在JavaScript中以编程方式触发onmouseover事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文