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
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.