当我将新表格行插入表格时,我需要重命名一个复选框。对皮特的爱,我不知道为什么这不起作用
$('.productSelect').blur(function() {
$('#invoiceTable tbody>tr:last').clone(true)
.insertAfter('#invoiceTable tbody>tr:last').find("input").val("")
.find("select").val("").find("checkbox")
.attr('name', "soldOut[" +rowCount + "]");
rowCount++;
return false;
});
HTML:
<tr>
<td><img src="/pics/deleteRow.png" class="delete"> </td>
<td class="productColumn">
<select name="productID[]" class="productSelect" >
<option value="0"></option>
</select>
</td>
<td>
<select name="lotID[]" class="lotNumber" >
<option value=0>Lot #</option>
</select>
</td>
<td>
<select name="wheelID[]" class="wheelNumber">
<option value=0>Wheel</option>
</select>
</td>
<td>
<select name="packageType[]" class="packageType">
<option value=0>Pkg Type</option>
</select>
</td>
<td class="numberPieces"><input name="numberPieces[]" class="numberOfPieces"></td>
<td class="quantityField"><input name="weight[]" class="weight" ></td>
<td class=priceField><input name="price[]" type="number" step="any">
</td>
<td class="subtotalField"><input type="number" step="any" readonly="readonly"></td>
<td class="soldOut"><input type="checkbox" name="soldOut[<?php echo $rowNum; ?>]" class="soldOutBox" ></td>
知道问题是什么吗?
答案 0 :(得分:2)
当你做一个find()时,你需要做一个.end()回到堆栈中,这样你就可以回到上一个元素了
$('div').find('span') // you are now at the span level.. so you have to do
$('div').find('span').end() // to get back at the div level
另一个例子
$('div').find('p').find('span') // <-- you are at the span level
$('div').find('p').find('span').end() // <-- you are now at the p level
$('div').find('p').find('span').end().end() // back at the div level
所以你必须这样做
$('#invoiceTable tbody>tr:last').clone(true)
.insertAfter('#invoiceTable tbody>tr:last').find("input").val("").end() // add end
.find("select").val("").end() // add end
.find("checkbox").attr('name', "soldOut[" +rowCount + "]");
另一个错误就是这个
.find("checkbox") // <-- there are no checkbox elements
将其更改为此
.find("input[type=checkbox]") // they are input with type=checkbox