html 鼠标停在表格行上面,那一行就换一个背景色。用 jquery / js 怎么做?

<tr><td></td><td></td><td></td><td></td></tr>ff,chrome都支持css里hover。即:tr:hover{backgro... <tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
ff,chrome都支持css里hover。即:tr:hover{background:#ccc;}
但在ie8里面tr就不支持:hover。并且也不支持:css background-color,不知道为什么?

所以想到了用onmouseover事件。和onmouseout事件。
但不知道怎么写,求帮助。
展开
 我来答
shy2850
2012-10-14 · TA获得超过6773个赞
知道大有可为答主
回答量:2505
采纳率:55%
帮助的人:1554万
展开全部
IE历史版本对于hover这个CSS伪类的解析只能识别在a:href标签上面,其它的一概不认识。

jQuery做过兼容了,直接jQuery("tr").hover(function(){jQuery(this).css({'background':'#ccc'});},function(){jQuery(this).css({'background':'none'});});

hover中两个function参数分别对应: mouseover和mouseout,jQuery已经做了包装。
追问
ie8下面没有作用,不知道为什么,其它下面正常
度老虎
2012-10-14 · TA获得超过1546个赞
知道大有可为答主
回答量:1661
采纳率:100%
帮助的人:2300万
展开全部
<table border=2>
<tr onmouseover="this.style.backgroundColor='#ccc';" onmouseout="this.style.backgroundColor='#fff';">
<td>111</td>
<td>222</td>
<td>333</td>
<td>444</td>
</tr>
</table>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友8c1745617
2012-10-14 · TA获得超过980个赞
知道小有建树答主
回答量:935
采纳率:0%
帮助的人:752万
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("table tr").hover(function(){
$(this).css("background-color","red");
},function(){
$(this).css("background-color","");
});
});
</script>

<title>无标题文档</title></head>
<body>
<table width="347" border="1">
<tr>
<td width="59"> </td>
<td width="170"> </td>

<td width="96"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>

没有ie8 我测试不了 其他的浏览器我试过了没事
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xuanyuan1332
2012-10-14
知道答主
回答量:13
采纳率:0%
帮助的人:4.5万
展开全部
不使用CSS,你可以在js里使用document.getelementById(‘id’).dgcolor="";具体用法如下:
<body>
<table>
<tr>
<td id="td_id" onmouseover="dgcolorchange()" onmouseout="dgcolorrenew()"></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
<script>
function dgcolorchange(){
document.getelementById('td_id').dgcolor="red";
}
function dgcolorrenew(){
document.getelementById('td_id').dgcolor="";
}
</script>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式