我有一张这样的桌子。
<table id="order-table">
<tr class="row-header">
<td style="width: 80px;">Line #</td>
<td style="width: 100px;">ID #</td>
<td style="width: 50px;">Qty</td>
<td style="width: 100px;">Desc</td>
<td style="width: 100px;">ABC8</td>
<td style="width: 100px;">UPC</td>
<td style="width: 100px;">NDC</td>
</tr>
<tr class="row">
<td style="width: 80px;"><input class="row-target" readonly tabindex="-1" style="width: 80px; background: lightgray" type="text" value="10"></td>
<td style="width: 100px;"><input class="id-target" style="width: 100px;" type="text" /></td>
<td style="width: 50px;"><input class="qty-target" style="width: 50px;" type="text" /></td>
<td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td>
<td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td>
<td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td>
<td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td>
</tr>
</table>
还有一些像这样的jQuery:
function checkIdTarget(rownum) {
if ($(this).val().length === 8) {
var rownum = $(this).parent("td").children(".row-target").val();
alert (rownum);
var newrow = '<tr class="row"><td style="width: 80px;"><input class="row-target" readonly tabindex="-1" style="width: 80px; background: lightgray" type="text" value="' + rownum + '"></td><td style="width: 100px;"><input class="id-target" style="width: 100px;" type="text" /></td><td style="width: 50px;"><input class="qty-target" style="width: 50px;" type="text" /></td><td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td><td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td><td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td><td style="width: 100px;"><input readonly tabindex="-1" style="width: 100px; background: lightgray" type="text" /></td></tr>';
$(newrow).insertAfter($(this).parents("tr"));
$("#button-submit-order").button("enable");
}
if ($(this).val().length > 8) {
var x = $(this).val();
$(this).val(x.slice(0, -1));
$(this).effect("shake");
}
if (isNaN($(this).val())) {
var x = $(this).val();
$(this).val(x.slice(0, -1));
$(this).effect("shake");
}
}
我正在尝试从输入框中获取与row-target
我正在调用的当前 ID 框相关的类的值this
。该值返回未定义。我究竟做错了什么?