Hover (over, out) is a method used to simulate a hover event. The following example shows how to use jquery to implement the table's color replacement function. If you are interested, refer
JQuery hover event
Hover (over, out) is a method that imitates a hover event (move the mouse over an object and remove it from it. This is a custom method that provides a "Keep in it" status for frequently used tasks.
When you move the cursor over a matching element, the specified first function is triggered. When you move the cursor out of this element, the specified second function is triggered. In addition, it will be accompanied by detection of whether the mouse is still in a specific element (for example, an image in p). If yes, it will continue to remain in the "hover" state, instead of triggering the removal event (corrected a common error in using the mouseout event ).
Parameters:
Over (Function): the Function to be triggered when you move the cursor over the element.
Out (Function): the Function to be triggered by removing the mouse from the element.
Example:
Hover the mouse over a table and add a specific class
JQuery code:
The Code is as follows:
$ (". Table_list tr"). hover (
Function (){
$ (This). addClass ("hover ");
},
Function (){
$ (This). removeClass ("hover ");
}
);
Pay attention to the following points:
1. hover is a class, and you can write the desired effect on your own.
2. Do not forget to introduce the jquery. js file. Otherwise, an error will be reported if it does not work.
3. Compared with traditional css, such as this. bgColor = 'red', it is much simpler and does not need to be added in one row.
4. Of course, the effects of parity rows can be different. Let's study it by yourself.
Today, we found that a simpler method is to use jquery's each method. This requires only one line of code to achieve the effect of line-by-line color change. However, it will not change as the mouse moves.
The Code is as follows:
$ (". Tablist tr "). each (function (I) {this. style. backgroundColor = ['# ccc', '# fff'] [I % 2]});