<table>
     <tbody>
        <tr contactName="1">
         <td>fda</td>
      </tr>
       <tr contactName="2">
         <td>fda</td>
      </tr>
     </tbody>
   </table>
       $(".edit").click(function(){
        index=$(this).parents("tr").index();
        })
    $("#contactTable tbody tr[contactName='1']").not(":eq("+index+")").length查找所有tr中是否包含contactname=1的值,但要我要排除tr中eq为index索引
上面的jq代码并不会达到我的要求,请哪位帮忙看下,谢谢了

解决方案 »

  1.   

    $(".edit").click(function(){
            index=$(this).parents("tr").index();
    $("#contactTable tbody tr[contactName='1']").not(":eq("+index+")").length
    })
      

  2.   

    <script type="text/javascript">
    $(function(){
        var o=$("#tabletest tbody tr").not($("#tabletest tbody tr").eq(1)).filter("[contactName='1']")
        o.each(function(){
            alert($(this).html())
        })
    })
    </script>
      <table id="tabletest">
         <tbody>
            <tr contactName="1">
             <td>1</td>
          </tr>
           <tr contactName="1">
             <td>2</td>
          </tr>
          <tr contactName="2">
             <td>3</td>
          </tr>
          <tr contactName="1">
             <td>4</td>
          </tr>
         </tbody>
       </table>
      

  3.   

    $("#contactTable tbody tr").not($("#contactTable tbody tr").eq(1)).filter("[contactName='1']")
      

  4.   

    csdn一直这么抽抽,谁受得了呀。唉。发贴老是不见,刷新N百回才见新贴<script type="text/javascript">
    $(function(){
        var o=$("#contactTable tbody tr").not($("#contactTable tbody tr").eq(1)).filter("[contactName='1']")
    //o.length就是你要的长度了,这是each给你看一下取到的对象对不对
        o.each(function(){
            alert($(this).html())
        })
    })
    </script>
      <table id="contactTable">
         <tbody>
            <tr contactName="1">
             <td>1</td>
          </tr>
           <tr contactName="1">
             <td>2</td>
          </tr>
          <tr contactName="2">
             <td>3</td>
          </tr>
          <tr contactName="1">
             <td>4</td>
          </tr>
         </tbody>
       </table>
      

  5.   

    Lz,按以下这样子吧,我优化了一下,可读性也应该增强了,里面也可以写成多条件
    var o=$("#contactTable tbody tr").not(function(i){return i==index}).filter("[contactName='1']")