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以下的某个子元素啊??

解决方案 »

  1.   

     
                  $("tr").filter(function(){
                    return $('td',this).length && !$('table',this).length
                 }).css({ background:"ffffff" }).hover(
                        function(){$(this).css({background:"#C1DAD7"});},
                        function(){$(this).css({background:"#ffffff"});}
                 );
      

  2.   


    <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>
      

  3.   

    return $('td',this).length && !$('GridView1',this).length什么意思
      

  4.   

    返回的是0或者是1,看到&&操作没?
      

  5.   


    $("table tr").mouseover(function(){
           $(this).addClass("background").siblings().removeClass("background");
    });html:<table width="200" border="1">
      <tr>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
      </tr>
      <tr>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
      </tr>
      <tr>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
      </tr>
    </table>css:.background{
    background:red;
    }
      

  6.   

    可以试试这个
    <!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>