我在一个单元格[6]上有一个带有复选框的网格,我尝试使用许多方法来获取此复选框的状态,例如:
的html
<tr>
<td hidden id='tableRowId'> + obj.itemId + </td>
<td><input type='checkbox' name='sel' class='chcktbl' id='ckh' value=' + obj.partNumber + '/></td>
<td> + obj.partNumber + </td>
<td> + quantidade + </td>
<td> + txtDesconto + %</td>
<td> + obj.leadTime + </td>
<td><input type='checkbox' name='sel' class='chcktbl' id='ckhLeadTime' onclick='leadTimeStateChanged(this)' value='0' /></td>
<td><input type='date' class='form-control form-control-sm' id='txtDataEntrega' onchange='onFocusOutDataEntrega(this)' /></td>
<td><a data-value=' + obj.partNumber + ' onclick=GetDetalhesItemTotvs(' + obj.partNumber + ', + quantidade + , + txtDesconto + ) href='javascript:void(0)' class='btnEdit'>Detalhes</a></td>
</tr>
我的js代码:
function leadTimeStateChanged(checkbox) {
if (checkbox.checked) {
checkbox.setAttribute('value', '1');
checkbox.setAttribute('checked', true);
}
else {
checkbox.setAttribute('value', '0');
checkbox.setAttribute('checked', false);
}
}
function xxxx() {
var rowIndex = 0;
var t = document.getElementById('itensTBody');
$("#itensTBody tr").each(function () {
alert(t.rows[rowIndex].cells[6].val());
alert(t.rows[rowIndex].cells[6].value);
alert(t.rows[rowIndex].cells[6].checked);
alert(t.rows[rowIndex].cells[6].prop('checked'));
alert(t.rows[rowIndex].cells[6].is(':checked'));
var tmpItem = {
PropostaItemId: $(t.rows[rowIndex].cells[0]).text(),
PartNumber: $(t.rows[rowIndex].cells[2]).text(),
Quantidade: parseInt($(t.rows[rowIndex].cells[3]).text()),
Desconto: parseFloat($(t.rows[rowIndex].cells[4]).text()),
MostraLeadTime: $(t.rows[rowIndex].cells[6]).is(':checked'),
//DataDeEntrega: $(t.rows[rowIndex].cells[7]).text(),
}
obj.ItensProposta.push(tmpItem);
rowIndex++;
});
}
答案 0 :(得分:0)
仅用于获取复选框的值:
//...
alert($('input', t.rows[rowIndex].cells[6]).is(":checked"));
//...