当前位置:Gxlcms > JavaScript > jQuery表格行换色的三种实现方法_jquery

jQuery表格行换色的三种实现方法_jquery

时间:2021-07-01 10:21:17 帮助过:4人阅读

代码如下:

$('tr').hover(function(event) {
$(this)[ (event.type == 'mouseenter' ? 'add' : 'remove') + 'Class' ]('test'); //test是样式
});

$('tr').hover(function(event) {
$(this).toggleClass('test'); //test是样式
});

$('tr').hover(function(){
$(this).addClass('test'); //test是样式
},function(){
$(this).removeClass('test'); //test是样式
});

注:一般情况下使用第二种方法是可以的,但是遇到表格行可以拖拽的情况,那么就会出现BUG了,这个自行测试就知道了。

人气教程排行