$("tr").each(function(index,item){ //遍历tr
if(index%2===0){ //下标除去2,判断偶数,0/2=0,2/2=0
$(item).css("backgroundColor","rgba(0,0,0,0.1)").hover(function(){ //这个是hover进入函数,这个函数是划入执行
$(this).css("backgroundColor","rgba(0,0,0,0.3)")// 条件判断符合进入,设置该原本背景,再添加交互效果
// 这里要考虑到hover(划入,滑出)
},function(){//hover滑出函数,
$(this).css("backgroundColor","rgba(0,0,0,0.1)")
})
}else{//这个用于划入不是偶数列队
$(item).hover(function(){
$(this).css("backgroundColor","rgba(255,0,0,0.1)")
},function(){
$(this).css("backgroundColor","rgba(255,0,0,0)")
})
}
})
知识点
each()深入了解
hover(划入函数,滑出函数)
index 下标
this 当前
%2 ===0
效果: