Event handling in jquery User Manual (7)

Source: Internet
Author: User

Jquery event handling methods:
Hover(Function, function)
Move the cursor
The first function is triggered when over, and the second function is triggered when the mouse moves out.
Style:

<Style>. Red {color: # ff0000} </style>

HtmlCode:

<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,
Function)
The first function is triggered when the matching element is clicked for the first time, and the second function is triggered when the element is clicked for the second 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.

In addition, jquery event processing also includes:
Bind(Type,
FN) is used to bind an event and trigger event to a matching object.
Trigger(Type) is a type event triggered by the user. $ ("P"). Trigger ("click ")
And unbind (); unbind (type,
FN)

Dynamic event(Function)
Simple Method for binding and unbinding 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 include the following:

    • 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); 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.

The events listed above for browers, form, keyboard, mouse, and UI can all be extended as described above.

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.