针对所有table表的tr:
$(function(){ $("tr").click(function(){ $("tr").css("background-color",""); $(this).css("background-color","#ff0f0f"); }); });
若只想对某一个table产生效果则在tr前添加上table的id:
$(function(){ $("#simple-table tr").click(function(){ $("tr").css("background-color",""); $(this).css("background-color","#ff0f0f"); }); });