Demo7.
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This). removeClass ("over") ;}) // remove the class of the row
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
In terms of the effect, I added a line to the color:
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This). removeClass ("over") ;}). click (function () {// remove the class of the row
$ (This ). toggleClass ("click "). removeClass ("alt")}) // click to change the color. Note: because there is a line to change the color, you must remove ("alt") When toggleClass is triggered ").
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
Speaking of this, I have to mention the difference between toggle and toggleClass:
$ (Document). ready (function () {// This is the legendary ready
$ (". Stripe tr"). mouseover (function (){
// If you move the cursor over the tr of the table whose class is stripe, execute the Function
$ (This). addClass ("over") ;}). mouseout (function (){
// Add the class value to this row as over, and execute the function when the mouse clicks this row
$ (This ). removeClass ("over ");}). toggle (function () {$ (this ). addClass ("click") ;}, function () {$ (this ). removeClass ("click ");}). unbind ("click ")
$ (". Stripe tr: even"). addClass ("alt ");
// Add the value of class to the even row of the table whose class is stripe as alt
});
We can find that:
ToggleClass: it can be found that the hyper-connection can still be connected, not occupied by toggle and click
Toggle: it can be found that the super connection is no longer available, so toggle is not suitable for this situation. However, you can unbind a click ("click"). The amount of code seems to be much larger than that of toggleClass in combination with click, so I chose toggleClass.
From: http://hi.baidu.com/hbjinzhao/blog/item/7609123b481d33e714cecb2c.html