使用jquery改变tr的背景色,有错。求帮助

$("#taobaolist tr").live("mouseover", function () {
alert("22");
this.css({"background-color":red});
this.attr("background-color",'red');
});

能alert出来,但使用attr或者css都没有改变啊,请问哪里有错,如何改呢?

$("#taobaolist tr").live("mouseover", function () {
alert("22");
$(this).css({"background-color":red});
});

css是jQuery对象的方法,不是javascript原生dom对象的方法,不能用this直接使用,需要包装成jQuery对象。
上面同学的方案会将同组下所有的tr都变色。追问

赞同最后一句,但我用的就是Jquery啊。。
找到了答案了,$(this).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-02-12
这个方法里的this指的是function里的this,所以不能直接用this调用
$("#taobaolist tr").live("mouseover", function () {
$("#taobaolist tr").css({"background-color":“red”});
});
这样试试看追问

这样不是每个tr都变色了么?现在只需要那个鼠标悬浮在上面的tr变色的。

第2个回答  2012-02-12
应该用$(this) 来代替this ,this 是DOM对象 ,$(this)才是JQUERY对象。shy2850 说的很对追问

哦,原来误解楼上了,谢谢各位。

相似回答