今天做一个项目,遇到了一个问题,是以前没有遇到过的,就此记上一笔。
1、trigger方法解释
官方是这么解释的:
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()代替。
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级