asp.net中 gridview的生成table,标题行是<tr><th>title</th></tr>的格式。
现在想要在除标题行以外鼠标move过有变色效果。
这样是可以实现的。
$(document).ready(function()
{
var bgcolor;
$('#GridView1 td').hover(function()
{
bgcolor=$(this).css('background-color');
$(this).parent().css('background-color','#faa');
},
function()
{
$(this).parent().css('background-color',bgcolor);
}
);
}
);但是
$('#GridView1 tr').notcontains[th].hover(function()
为什么不行。
在jquery中如何排除tr以下的某个子元素啊??
现在想要在除标题行以外鼠标move过有变色效果。
这样是可以实现的。
$(document).ready(function()
{
var bgcolor;
$('#GridView1 td').hover(function()
{
bgcolor=$(this).css('background-color');
$(this).parent().css('background-color','#faa');
},
function()
{
$(this).parent().css('background-color',bgcolor);
}
);
}
);但是
$('#GridView1 tr').notcontains[th].hover(function()
为什么不行。
在jquery中如何排除tr以下的某个子元素啊??
$("tr").filter(function(){
return $('td',this).length && !$('table',this).length
}).css({ background:"ffffff" }).hover(
function(){$(this).css({background:"#C1DAD7"});},
function(){$(this).css({background:"#ffffff"});}
);
<script>
$(document).ready(function() {
var bgcolor;
$('#<%= gv.ClientID%> tr:not(:has("th"))').hover(function() {
bgcolor = $(this).css('background-color');
$(this).css('background-color', '#C1DAD7');
},
function() {
$(this).css('background-color', bgcolor);
}
);
}
); </script>
$("table tr").mouseover(function(){
$(this).addClass("background").siblings().removeClass("background");
});html:<table width="200" border="1">
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
</table>css:.background{
background:red;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<style type="text/css">
tr, td
{
border: 1px solid black;
}
</style>
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$().ready(function () {
$("tr").filter(function () {
return $('td', this).length && !$('table', this).length
}).css({ background: "ffffff" }).hover( function () { $(this).css({ background: "#C1DAD7" }); },
function () { $(this).css({ background: "#ffffff" }); }
);
});
</script>
</head>
<body>
<table style="border: 1px solid black;">
<tr>
<td>
2
</td>
<td>
5
</td>
<td>
7
</td>
</tr>
<tr>
<td>
2
</td>
<td>
5
</td>
<td>
7
</td>
</tr>
<tr>
<td>
2
</td>
<td>
5
</td>
<td>
7
</td>
</tr>
</table>
</div>
</body>
</html>