Jquery user manual 6-event handling Author: CHOY

Source: Internet
Author: User
Sat. : Event Processing

  Hover (function, function) triggers the first function when the mouse moves over, and triggers the second function when the mouse moves out.
Style: <style>. Red {color: # ff0000} </style>
HTML code: <Div id = "A"> SDF </div>
Jquery code and Effects

$ (Function (){
$ ("# A"). Hover (function () {$ (this). addclass ("red ");},
Function () {$ (this). removeclass ("red ");
});
})

The final result is that when you move the mouse over the layer with ID a, a red style is added to the layer and the red style is removed when the layer is left.

Toggle (function) triggers the first function when a matching element is clicked for the first time.
Style: <style>. Red {color: # ff0000} </style>
HTML code: <Div id = "A"> SDF </div>
Jquery code and Effects

$ (Function (){
$ ("# A"). Toggle (function () {$ (this). addclass ("red ");},
Function () {$ (this). removeclass ("red ");
});
})

The final effect is to add a red style to the layer when you click the layer with ID a and remove the red style when you leave the layer.

The BIND (type, FN) User binds an event and the method of triggering the event to the matching object.
Trigger (type) triggers type-based events. $ ("P"). Trigger ("click ")
Also:Unbind () unbind (type, FN)

Dynamic event (function) binding and unbinding provides a simple method for Functions
Example:

$ ("# A"). BIND ("click", function (){
$ (This). addclass ("red ");
})

You can also write as follows:

$ ("# A"). Click (function (){
$ (This). addclass ("red ");
});

The final effect is to add a red style to the layer when you click the layer with ID,

Functions provided by jquery
Used for browers events
Error (FN) load (FN) unload (FN) resize (FN) scroll (FN)

Used for Form Events
Change (FN) Select (FN) Submit (FN)

Used for Keyboard Events
Keydown (FN) keypress (FN) keyup (FN)

Used for mouse events
Click (FN) dblclick (FN) mousedown (FN) mousemove (FN)
Mouseout (FN) Mouseover (FN) mouseup (FN)

Used for UI events
Blur (FN) Focus (FN)

The above events are extended to 5 categories.
For example, click (FN) extended click () unclick () oneclick (FN) unclick (FN)
Click (FN): adds an event that triggers a function when a click is added.
Click (): Click events that match objects can be executed in other events.
Unclick (): The Click Event of the matching object is not executed.
Oneclick (FN): adds a click event that can be executed once.
Unclick (FN): adds an event that does not trigger a function when a click is added.
Used for browers, form, and keyboard

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.