如何从jquery数据表中获取受第一列复选框约束的第二列单元格数组



我有一个如下的表

<table id="vainTbl6" class="dtable" cellpadding="3" cellspacing="1" border="0">
    <thead>
        <tr><th>check</td><th>Morphosal</th><th>goat </th><th>the other</th></tr>
    </thead>
    <tbody id="tbdy">
         <tr class="gradeX">
            <td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%">-Approve the femuneration Gommiqee purpirt</td>
            <td>pontpose</td></tr>
       <tr class="gradeX">
            <td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%">-Declare a final truce</td>
            <td>More</td></tr>
       <tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%">-Amend the articles of asscotonation</td>
            <td>Four</td></tr>
       <tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%">-Re-elect Bandanna la banana for warden</td>
            <td>Floor</td></tr>
    </tbody>
</table>

并且第一列是复选框。我需要获取第一列中复选框设置为true 的所有第二列单元格

我试着用这个,但没有用。

  function extractRowCell(divNode){
    alert(divNode.id);
    $('#tbdy tr td').each(function() {    
     alert('hello');
     var aRowData = this.cells
     alert(aRowData[1].firstChild.value);
             return aRowData;
     });
}

调用如下:

 <a id="la" href='#' onclick='extractRowCell(this.parentNode)' style="position:absolute; top:280px; left:350px;">Votes & Concerns</a>

函数中的警报会以正确的值触发。

TIA

要迭代td's,只需执行以下操作。

$('#tbdy tr td').each(function() {    
     alert( $(this).text() ); 
}); 

您可以执行此

<table><tbody id="tbdy">
<tr class="gradeX">
            <td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%" class="item">-Approve the femuneration Gommiqee purpirt</td>
            <td>pontpose</td></tr>
       <tr class="gradeX">
            <td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%" class="item">-Declare a final truce</td>
            <td>More</td></tr>
       <tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%" class="item">-Amend the articles of asscotonation</td>
            <td>Four</td></tr>
       <tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
            <td style="width:55%"  class="item">-Re-elect Bandanna la banana for warden</td>
            <td>Floor</td></tr>
</tbody>
</table>
<button>Get</button>
<script>
    $("button").click(function(){
    var ret="";
    $("#tbdy tr td:first").each(function()
    {
    if($("input:checked").length!=0)
    {       
        ret=$("input:checked").parent().parent().find("td.item").text();
    }       
    });
    alert(ret);
    });
</script>

最新更新