2010-12-08 10 views
1

グリッドビューでセルを選択する際に助けが必要です。私は現在確認された行のIDセルを選択する必要がJquery別のセルの状態に基づいてセル値を取得します。

<table> 
<tr> 
<th>CheckBox</th> 
<th>Customer ID</th> 
<th>First Name</th> 
<th>Last Name</th> 
</tr> 
<tr> 
<td>CheckBox</td> 
<td>1</td> 
<td>Joe</td> 
<td>Blogs</td> 
</tr> 
<tr> 
<td>CheckBox</td> 
<td>2</td> 
<td>Chris</td> 
<td>White</td> 
</tr> 
</table> 

:私はこのようなテーブルを持っています。あなたはどうしますか?

私は検索しましたが、上記のようなものは見つけられません。理論的には

+0

あなたの 'tr'要素には' id'属性がありません。本当のマークアップを投稿してください。 –

+1

@David Thomas - 私は 'id cell'が各行の2番目の列だと信じています。 – sje397

答えて

3
$(":checkbox").click(function(){ 
    if(this.checked){ 
     var id = $(this).parent().next().text();  
     // assuming your second column has id you're looking for [customer id] 
    } 
}); 
次の作品)のアクセスを容易にするため、 'ROWID'

wokring demo

2

、これは動作します:

$('input:checkbox').change(
    function(){ 
     if ($(this).is(':checked')) { 
      var theRowId = $(this).closest('tr').attr('id'); 
     } 
    }); 

A quick and dirty JS Fiddle demo


編集:私の質問、およびHTMLの誤解を償うために:あなたが見つけたい数が、私はクラスを割り当てた先のセル(セル内に格納されていることを考えると

$(document).ready(

function() { 
    $('.rowID').each(
     function(i){ 
      $(this).text(i+1); 
     }); 
    $('input:checkbox').change(

    function() { 
     if ($(this).is(':checked')) { 
      var theRowId = $(this).parent().siblings('.rowID').text(); 
      $('#rowId').text(theRowId); 
     } 
    }); 
}); 

JS Fiddle demo

0

さて、あなたの基本構造は次のとおりです。

<tr> 
<td>CheckBox</td> 
<td>2</td> 
<td>Chris</td> 
<td>White</td> 
</tr> 

だからこれはあなたの問題を解決することがあります。

$(document).ready(function() 
{ 
    $('tr td').find('checkbox').click(function() 
    { 
     var line_id = $(this).parent('td').next().text(); 
    }); 
}); 

私はそれが役に立てば幸い! ^^

関連する問題