0

新しいテーブル行をテーブルに挿入するときに、チェックボックスの名前を変更する必要があります。ピートの愛のためにこれがうまくいかない理由はわかりません

$('.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>

問題が何であるかについて何か考えはありますか?

4

1 に答える 1

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

フィドル

于 2013-03-02T17:05:20.840 に答える