Use the jqueryhover event to implement the table's line-by-line Color Conversion Function example _ jquery-js tutorial

Source: Internet
Author: User
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]});

Related Article

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.