2016-04-04 18 views
-5
<table> 
    <tr> 
    <td><textarea>col 1, row 1</textarea></td> 
    <td><textarea>col 2, row 1</textarea></td> 
    <td><textarea>col 3, row 1</textarea></td> 
    </tr> 
    <tr> 
    <td><textarea>col 1, row 2</textarea></td> 
    <td><textarea>col 2, row 2</textarea></td> 
    <td><textarea>col 3, row 2</textarea></td> 
    </tr> 
    <tr> 
    <td><textarea>col 1, row 3</textarea></td> 
    <td><textarea>col 2, row 3</textarea></td> 
    <td><textarea>col 3, row 3</textarea></td> 
    </tr> 
    <tr> 
    <td><textarea>col 1, row 4</textarea></td> 
    <td><textarea>col 2, row 4</textarea></td> 
    <td><textarea>col 3, row 4</textarea></td> 
    </tr> 
</table 

私がcol 1、row 2をクリックすると、すべての行からすべての値col 1を取得し、この値以外の配列に保存する方法はありますか?あなたがいずれかをクリックしたときにそのようjqueryで同じ列のすべてのtd値を取得するには?

+1

選択する手段は何ですか? –

+0

選択は、をクリックすることを意味します。 –

+0

しかし、あなたはtdの中にテキストエリアを持っています。どのようにそれをクリックしますか? –

答えて

1
$('td').click(function() { 
    var colIndex=$(this).index(); 
    var allCellsOnTheColumn=$(this).closest('table').find('tr').find('>td:eq('+colIndex+')'); 
    var allCellsWithoutThisOne=allCellsOnTheColumn.not(this); 
    console.log(allCellsWithoutThisOne); 
}); 

このコードは、すべてのTDのクリックハンドラを追加します、それは意志1を除いて、同じ列にconsole.logすべてTDは、クリックされました。それはあなたが望んだことですか?

関連する問題