[英]Select td elements if checkbox is on
我有這張表,如果checked
該復選框,我想從中獲取 select 的所有td
元素值,然后將所有元素放入某個數組或字符串中,以便我可以將其傳輸到服務器端。
<table id="tableDg">
<tbody>
<tr>
<td><input type="checkbox" class = "chkbCsm" ></input></td>
<td width="10%" align="center"> <input type="hidden" id="nameText" readonly="true" value="{name}">{name}</input></td>
<td width="22%" align="center"> <input type="hidden" id="nameText" readonly="true" value="{host}">{host}</input></td>
</tr>
</tbody>
</table>
這是我在 jquery 方面所做的事情,但無論復選框是否打開,它都會進行選擇。 請有人幫我把它放在一些陣列中。
$('#tableDg tbody tr').live('click', function (event) {
$(this).find('td').each( function( index, item ) {
if ( $(this).has(':hidden') ) {
alert( $(this).find(':hidden').val() );
}
});
});
添加了一個 jsFiddle 鏈接
看看這里
$('#tableDg tbody tr').live('click', function (event) {
if ($('input.chkbCsm', this).is(':checked'))
{
$('input:hidden', this).each(function() {
alert(this.value);
});
}
});
您沒有檢查代碼中是否選中了復選框。
if($(".chkbCsm:checkbox").is(":checked")
{
$(this).find('td').each( function( index, item ) {
if ( $(this).has(':hidden') ) {
alert( $(this).find(':hidden').val() );
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.