300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > jquery中trigger()无法触发hover事件的操作【jquery】

jquery中trigger()无法触发hover事件的操作【jquery】

时间:2024-07-31 03:27:23

相关推荐

jquery中trigger()无法触发hover事件的操作【jquery】

web前端|js教程

jquery,trigger(),无法触发hover

web前端-js教程

今天做一个项目,遇到了一个问题,是以前没有遇到过的,就此记上一笔。

黑锐源码论坛,vscode的项目属性在哪里,ubuntu使用pluma,允许Tomcat长等待,airtest爬虫集群,php薪资待遇,南京seo排名优化公司排名,全屏滚动网站lzw

1、trigger方法解释

vb6 二维码生成源码,vscode80字符提示线,ubuntu下make,php与iis和tomcat,pycharm运行爬虫,php简易计算器,杭州湾新区seo选哪家lzw

官方是这么解释的:

原生app有源码么,vscode快捷键运行,ubuntu配置 jre,用tomcat看视频,网络爬虫分享,PHP是否支持MySQL,兰州整站seo优化代理公司,资源类网站 源代码,ecshop模板如何制作lzw

Description: Execute all handlers and behaviors attached to the matched elements for the given event type.

用法:

.trigger( eventType [, extraParameters] )

其中eventType包含javascript内置的事件、jQuery增加的事件和自定义事件。例如:

$(#foo).bind(click, function(){ alert($(this).text());});$(#foo).trigger(click);$(#foo).bind(custom, function(event, param1, param2){ alert(param1 + "\n" + param2);});$(#foo).trigger(custom, [Custom, Event]);

很强大,常常用于页面初始化的时候使用。

2、trigger遇到hover

var $search=$(#header .search);$search.find(li).hover(function(){ alert(1);},function(){ alert(2);});$search.find(li).eq(0).trigger(hover);

无法触发hover。但是:

var $search=$(#header .search);$search.find(li).click(function(){ alert(1);},function(){ alert(2);});$search.find(li).eq(0).trigger(click);

触发click正常!

解决办法:

var $search=$(#header .search);$search.find(li).hover(function(){ alert(1);},function(){ alert(2);});$search.find(li).eq(0).trigger(mouseenter);//hover修改为mouseenter/mouseleave/mouseover/mouseout

同样的情况存在于jQuery.live(),不过live不推荐在1.7以后版本使用,使用on()代替。

以上所述就是本文的全部内容了,希望大家能够喜欢。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。