Trigger () Trigger event
Triggering events is similar to clicking on the click, MouseOver, KeyDown and other actions of the JS event, simply said is an action, may be asked, that show, hide is not? No
Why use Trigger ()?
For example: You add a click Click event to a button, and the code below is displayed.
var div = $ ("#mybutton"); Your button. Div.click (function () {alert (' You are a pig, ~ let you point, you point? ‘);});
The above code is a button's click event. This time you have a non-demand, is to want to refresh the page when you click on this button. If you do not need trigger () you can write in the following way:
Div.click ();
If you use trigger (), you will write this: the effect is the same as the above sentence, that is, a little longer.
Div.trigger ("click");
Then someone said: You are a pig Ah ~~ above this short point, you also teach me to use the following =,=
Watch me, ~? Keep looking down.
You use the index in the manual. Click to see two results click () and, click (FN), and then search trigger found only one trigger (type, [data]).
And then you know what I mean. -trigger can pass parameters in.
Let's look at the trigger example in the Handbook:
$ ("P"). Click (Function (event, a, B) {//A normal click event, A and B are undefined types//if triggered with the following statement, a points to "Foo" and B points to "bar"}). Trigger ("clic K ", [" foo "," Bar "]);
Do you understand? If you use the click, it does not eat the parameters, with trigger words, you can eat.
Practice it: stick to your page and try it, and remember to load jquery in.
$ (function () {var div = $ ("#mybutton");//Your button. Div.click (function (e,text) {var text = text | | ' You are a pig, ~ let you point, you point? ‘; alert (text); }); Div.trigger ("Click", "Hello, please click button");});
Demo
The following code can display a "Hello World" JQuery Code: $ ("P"). Bind ("MyEvent", Function (event, Message1, Message2) {