<table width="200" border="0" align="left" cellpadding="0" cellspacing="0" class="tab">
<tbody>
<tr>
<td height="25">内容</td>
</tr>
</tbody>
<tbody onclick="jumpRight()">
<tr>
<td height="25首页1</td>
</tr>
</tbody>
<tbody onclick="jumpRight()>
<tr>
<td height="25>首页2</td>
</tr>
</tbody>
</table> 调用onclick事件的时候希望把对应的tbody的背景颜色变红本来希望使用jquery$(this).addClass("tr_on") 无效果求教高手,调用onclick事件的时候 如何可以获得当前元素并添加背景样式
<tbody>
<tr>
<td height="25">内容</td>
</tr>
</tbody>
<tbody onclick="jumpRight()">
<tr>
<td height="25首页1</td>
</tr>
</tbody>
<tbody onclick="jumpRight()>
<tr>
<td height="25>首页2</td>
</tr>
</tbody>
</table> 调用onclick事件的时候希望把对应的tbody的背景颜色变红本来希望使用jquery$(this).addClass("tr_on") 无效果求教高手,调用onclick事件的时候 如何可以获得当前元素并添加背景样式
{
$(obj).addClass("tr_on")
}json对象和js对象得做转换
改为
<tbody onclick="jumpRight(this)">
function jumpRight(obj)
{
$(obj).addClass("tr_on")
}
td{cursor:pointer;}
</style>
<table width="200" border="0" align="left" cellpadding="0" cellspacing="0" class="tab">
<tbody>
<tr>
<td height="25">内容</td>
</tr>
</tbody>
<tbody>
<tr>
<td height="25">首页1</td>
</tr>
</tbody>
<tbody>
<tr>
<td height="25">首页2</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function jumpRight(){
$("tbody").each(function(i){
$(this).click(function(){
var gb=$(this).css("background");
if(gb!="#f00"){
$(this).css("background","#F00");
}else{
$(this).css("background","#FFF");
}
});
if(i>$("tbody").lenth)
return false;
});
}
jumpRight();
</script>