JQuery Event Binding (event) Learning notes

Source: Internet
Author: User

This article mainly records the processing of jquery event response

Bind (type, data, FN) determine the event for all selected element, type is the event type, data is the parameter, and FN is the method of handling the matter.

Eg:1. $ ("P"). Bind ("click", Function () {Alert ($ (this). text ());

2. Function handler (event) {alert (event.data.foo);}

$ ("P"). Bind ("click", {foo: "Bar"}, Handler) ==>alert ("Bar")

Blur () triggers the Blur method, Blur (FN) sets the Blur function

Eg: <p>Hello</p>

$ ("P"). blur (function () {alert ("Hello");}); ==>

<p onblur= "alert (' Hello ');" >Hello</p>

Change (FN) method for setting the onchange event

Eg:<p>hello</p>

$ ("P"). Change (function () {alert ("Hello");}); ==><p onchange= "alert (' Hello ');" >Hello</p>

The onclick event is triggered by click (), click (FN) to set the OnClick method


DblClick (FN) Set OnDblClick method

55.error (FN) Set Error method

Focus () trigger Onfocus,focus (FN) Set the focus method

Eg:<p>hello</p>

$ ("P"). focus (function () {alert ("Hello");});

==><p onfocus= "alert (' Hello ');" >Hello</p>

Hover sets the event that is triggered when mouse is moved in and mouse is moved out.

Eg: $ ("P"). Hover (function () {
$ (this). addclass ("over");
},function () {
$ (this). AddClass ("Out");
});

KeyDown (FN), KeyPress (FN), KeyUp (FN), and keyboard-related actions correspond to onkeydown,onkeypress,onkeyup respectively.

MouseDown (FN), MouseMove (FN), Mouseout (FN), MouseOver (FN), MouseUp (FN) These are mouse related operations, respectively corresponding to Onmousedown,onmousemove, onmouseout,onmouseover,onmouseup.60 load triggers the eg <p>hello</p>$ ("P") when the element load event occurs. Load (function () { Alert ("Hello"); }); ==><p onload= "alert (' Hello ');" >Hello</p>

One (type, data, FN) is about the same as bind, and the biggest difference is that the first one runs once and then no longer responds. If you do not want to run the default method after running, you can return the value in FN as long as it returns false. Eg: <p>hello</p >$ ("P"). One ("click", Function () {Alert ($ (this). text ()); ==>alert ("Hello")

Ready (FN) when the DOM structure is loaded. When using this method, do not write code in the OnLoad method. Otherwise, it will not trigger the ready event, eg,

$ (document). Ready (function () {Your code here ...});

JQuery (function ($) {
Your code using failsafe $ alias here ...
});

Resize sets the OnResize method. Trigger When size changes

Eg: <p>hello</p>$ ("P"). Resize (function () {alert ("Hello");}); <p onresize= "alert (' Hello ');" >Hello</p>

Scroll (FN) Set Onscroll method

Select () triggers the Onselect method. Select (FN) Set Select method

Submit () submits the form and submit (FN) sets the Submit method. Eg: $ ("#myform"). Submit (function () {return $ (' input ', this). Val (). length > 0;}); <form id= "MyForm" ><input/></form>

Toggle (even, odd), even when an even click is run, odd runs when odd clicks. Delete with unbind (' click ')

Eg: $ ("P"). Toggle (function () {
$ (this). AddClass ("selected");
},function () {
$ (this). Removeclass ("selected");
});

Trigger (type) triggers the appropriate type method

Eg: <p click= "alert (' Hello ')" >hello</p>$ ("P"). Trigger ("click") ==>alert (' Hello ')

Unbind (Type, FN) is the opposite of bind,

Unbind () Delete all bindings

Eg:<p onclick= "alert (' Hello ');" >hello</p>$ ("P"). Unbind () ==>[<p>Hello</p>]

Unbind (type) deletes the specified binding

Eg:<p onclick= "alert (' Hello ');" >hello</p>$ ("P"). Unbind ("click") ==>[<p>Hello</p>]

Unbind (Type, fn) deletes the specified FN of the specified type

Eg:<p onclick= "alert (' Hello ');" >hello</p>$ ("P"). Unbind ("click", Function () {alert ("Hello");}) ==>[<p>Hello</p>]

Unload (FN) trigger method when page unload

Eg: <p>hello</p>$ ("P"). Unload (function () {alert ("Hello");}); ==><p onunload= "alert (' Hello ');" >Hello</p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.