In actual applications, check boxes may appear in the table. When deleting a table, delete the records of the rows where the check boxes are located. You can add a special effect here. When you click a row and select the check box of the row, the background color of the row is highlighted. Using jquery technology to operate the table is simple, with the jquery syntax, you can easily change the color of a table by row, and hover and highlight it. In actual applications, check boxes may appear in the table. When you delete a table, delete the record of the row where the check box is located. You can add a special effect here. Click a row and select the check box of the row. the background color of the row is also highlighted. This makes people feel very good.
The effect is as follows:
Here I have two functions:
Function 1. Click a row. The check box of the row is selected and the background color is changed.
Function 2. Click "select all" or "do not select all" to change the line color.
I encapsulated the two functions into the js file and introduced them when using them.
Let's take a look at the CSS code. I encapsulated it into a css file.
The Code is as follows:
. Selected {
Background: # FF6500;
Color: # fff;
}
Check the js file code:
Function 1 code:
The Code is as follows:
/**
* Set the background color in the table containing the check box.
*/
$ (Document). ready (function ()
{
/**
* The background color is changed when the table row is clicked.
*/
$ ("# Tablight tr: gt (0)"). click (function () // after obtaining the 2nd rows
{
If ($ (this). hasClass ("selected") // you can check whether the image is selected.
{
$ (This). removeClass ("selected"). find (": checkbox"). attr ("checked", false); // select the remove Style
}
Else // set the selected
{
$ (This). addClass ("selected"). find (": checkbox"). attr ("checked", true); // Add a style if it is not selected
}
});
});
Function 2 code:
The Code is as follows:
/**
* Change the background color after you click "select all" or "reselect ".
*/
Function setColor () // sets the background color of tr.
{
Var checkboxs = $ ("# tablight tr: gt (0) input [type = checkbox]"); // get all check boxes
Var boxeds = $ ("# tablight tr: gt (0) input [type = checkbox]: checked"); // obtain the selected check box
If (boxeds. length> 0)
{
Checkboxs. parent (). parent (). addClass ("selected"); // check box in td
}
Else
{
Checkboxs. parent (). parent (). removeClass ("selected ");
}
}
If you want the code to take effect, you need to add the id attribute to the table. The attribute value is "tablight". If you select all or do not select all, call the setColor method.