Today to do a project, encountered a problem, is not encountered before, to write a note on this.
1, Trigger method explanation
This is the official explanation:
Copy Code code as follows:
Description:execute all handlers and behaviors attached to the matched of the for the Elements event type.
Usage:
. Trigger (EventType [, Extraparameters])
Where EventType contains JavaScript-built events, jquery-added events, and custom events. For example:
$ (' #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 ']);
Very powerful, often used when page initialization is used.
2, Trigger met hover
var $search =$ (' #header. Search ');
$search. Find (' Li '). Hover (function ()
{
alert (1);
},function ()
{
alert (2);
});
$search. Find (' li ')-eq (0). Trigger (' hover ');
Unable to trigger hover. But:
var $search =$ (' #header. Search ');
$search. Find (' Li '). Click (function ()
{
alert (1);
},function ()
{
alert (2);
});
$search. Find (' li ')-eq (0). Trigger (' click ');
Trigger Click Normal!
Solution:
var $search =$ (' #header. Search ');
$search. Find (' Li '). Hover (function ()
{
alert (1);
},function ()
{
alert (2);
});
$search. Find (' li ')-eq (0). Trigger (' MouseEnter ');//hover modified to Mouseenter/mouseleave/mouseover/mouseout
The same situation exists in jquery.live (), but live is not recommended for use on the version after 1.7, using on () instead.
The above mentioned is the entire content of this article, I hope you can enjoy.