The previous blog wrote the check box. This time it wrote a single record. Sometimes, when querying, you can only select one record. If you highlight the row of the selected record, at the same time, the row's single-choice button is also selected, which will improve the user experience. Today's era is the era of user experience.
The effect is as follows:
The CSS file is as follows:
Copy codeThe Code is as follows:
. Selected {
Background: # FF6500;
Color: # fff;
}:
This Javascript file code becomes simpler, as shown below:
Copy codeThe Code is as follows:
/**
* Set the background color of the table containing the single-choice button.
*/
$ (Document). ready (function ()
{
/**
* The background color is changed when the table is clicked.
*/
$ ("# Tablight tr: gt (0)"). click (function () // get 2nd rows and later
{
$ (This ). addClass ("selected "). siblings (). removeClass ("selected "). end (). find (": radio "). attr ("checked", true );
});
});
To make the Code take effect, add the id attribute to the table. The attribute value is "tablight ". Once this is done, you only need to reference the two files when using it.