The
Today uses a concise method of toggleclass () to achieve alternate colors: The code is as follows:
The first is a more complicated approach:
$ (function ()
{
$ ("#table tr"). Hover (function ()
{
$ (this). addclass ("H");
},function ()
{
$ (this). Removeclass ("H");
})
$ ("Input"). Click (function ()
{
if ($ (this). attr ("checked"))
{
$ (this). Closest ("tr"). addclass ("C");
}
Else
{
$ (this). Closest ("tr"). Removeclass ("C");}}
)
The second simpler approach:
Toggleclass () Toggles one or more classes of the selected element to be set or removed.
This method examines the class specified in each element. Adds a class if it is not present, and deletes it if it is set. This is called the switching effect.
However, by using the "switch" parameter, you can specify that only the class be deleted or added.
$ (function () {
$ ("#table tr"). Hover (function () {
$ (this). Toggleclass ("H");
})
$ ("Input"). Click (function () {
var d = $ (this);
D.closest (' tr '). Toggleclass ("C", D.attr ("checked"))
})
</script>
</body>