jQuery怎么遍历表格,获取每一列的值.

解决方案 »

  1.   

    <!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" />
    <title>哥是传说一列</title>
    </head><body>
        <table border="1px" id="tb">
            <tbody><tr><td>哥是第一列</td><td>俺第二列的</td></tr>
            <tr><td>哥是传说一列</td><td>俺二列的</td></tr></tbody>
        </table>
        <script type="text/javascript">
            function getTableCell (obj){
        var _arrCellOnes =[];
        var _oTBody = obj.TBodies ? obj.TBodies : obj;
        var _oTRows = _oTBody.rows;
        for(i=0;i<_oTRows.length;i++){
            if(_oTRows[i].cells[0]){
                _arrCellOnes.push(_oTRows[i].cells[0].innerHTML);
            }
        }
        return _arrCellOnes;
    }
          var arrCells = getTableCell($("#tb"));//用到jQuery了
          alert(arrCells);
        </script>
    </body>
    </html>
      

  2.   

    <!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" />
    <title>js测试</title>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
       $("#tb tr").each(function(){
    var text = $(this).children("td:first").text();
    alert("text=="+text);
       });
    });
    </script>
    </head>
    <body>
    <table id="tb" width="200" border="1">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
      <tr>
        <td>yi</td>
        <td>er</td>
        <td>san</td>
      </tr>
      <tr>
        <td>一</td>
        <td>二</td>
        <td>三</td>
      </tr>
    </table></body>
    </html>
      

  3.   

    受不了,我的才是jquery的方法
      

  4.   

    jquery. var td = $("td");
    $.each(td, function(key, value){
        $(value).find("td")[0]; //这个也是第一个td. 另一种写法. 
    });
      

  5.   

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script language="javascript" src="jquery.js"> </script>
    <script language="javascript">
    $(document).ready(function(){
    $('td').each(function(){
    alert($(this).text());
    });
    });
    </script>
    </HEAD>
    <BODY>
       <table >
    <tr>
    <td>a</td>
    <td>a</td>
    </tr>
    <tr>
    <td>b</td>
    <td>b</td>
    </tr>
       </table>
    </BODY>
    </HTML>
      

  6.   

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script language="javascript" src="jquery.js"> </script>
    <script language="javascript">
    $(document).ready(function(){
    $('td').each(function(){
    alert($(this).text());
    });
    });
    </script>
    </HEAD>
    <BODY>
       <table >
    <tr>
    <td>a</td>
    <td>a</td>
    </tr>
    <tr>
    <td>b</td>
    <td>b</td>
    </tr>
       </table>
    </BODY>
    </HTML>
      

  7.   

    hehe ,最终大家还是把代码都贴上来了,我非常的感谢,今天我还在加班,就是遇到了这个问题,经过多个老兄的提示,我终于把问题搞定了,心里也踏实多了。
      

  8.   

    一楼的是纯javascript的写法,3楼以下的才是jquery的写法,不过应该都能用的,jquery的应该代码少点
      

  9.   

    哈哈,能解决就可以了,管他纯JavaScript还是jq呢