<table>
       <tr><td>第一行</td></tr>
        <tr><td> 第二行</td></tr>
        <tr><td>第三行</td></tr>
        <tr><td>第四行</td></tr>
        </table>
        <input type="button" id="btntesthide" value="testhide" />//语句1:
  $("#testhide").click(function() { $("tr:gt(2)").css({ background: "pink", color: "yellow" }) });
//语句2:
 $("#btntesthide").click(function() {
    $($("tr:even)")).each(function(index,fo) { $(fo).css({ background: "pink", color: "yellow" }) });
    });为什么语句2不对?

解决方案 »

  1.   


    $("#btntesthide").click(function() {
        $.each($("tr:even),function(index,fo){ 
                  $(fo).css({ background: "pink", color: "yellow" }) 
              }
        );
      

  2.   


    $("#btntesthide").click(function() {
        $.each($("tr:even),function(index,fo){ 
                  $(this).css({ background: "pink", color: "yellow" }) 
              }
        );
      

  3.   

    1楼,2楼我都试了
    还是不行啊,一点button按钮就会抛出2 个异常:
    1、行: 2832
    错误: 例外被抛出且未被接住
    2、行: 119
    错误: 对象不支持此属性或方法
      

  4.   

    sorry
    括号少了
    $("#btntesthide").click(function(){
        $.each($("tr:even),function(index,fo){ 
                  $(this).css({ background: "pink", color: "yellow" });
              });
        });