How to trigger mouseover function on an element when not really mouseovered

爷,独闯天下 提交于 2019-12-29 01:36:12

问题


In jQuery, is it possible for an element to act like it is mouseovered automatically when the page is loading, when it is not really mouseovered? I mean, I won't put my pointer on the desired element for it to do what it would do if I put.


回答1:


Use .trigger() to trigger an event.

$('#foo').trigger('mouseover');



回答2:


You can call the handler directly

$('abc').mouseover();



回答3:


Put the desired action in the document.ready function as that is when you actually want the action, not on a mouse-over that doesn't happen.



来源:https://stackoverflow.com/questions/15350603/how-to-trigger-mouseover-function-on-an-element-when-not-really-mouseovered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!