0

ボックスをチェックすると、同じ行の入力に値が入力されるという要件があります。

私のコードは次のとおりです。

function populatetransportprice() {
// iterate through the "checked" checkboxes
$("table.authors-list").find('input[type="checkbox"][name^="treated"]:checked').each(function () {
    alert(treatedtransportcostperton);
    row.find('input[name^="transportprice"]').val(treatedtransportcostperton.toFixed(2));
});      

}

各行の入力フィールドはtranpsortpriceX、X が行番号です。

私のHTMLは:

<table class="authors-list" id="ordertable">
<tr>
 <td><input name="transportprice1" id="transportprice1" class="rounded"></td>
</tr>
<tr>
 <td><input name="transportprice2" id="transportprice2" class="rounded"></td>
</tr>
<tr>
 <td><input name="transportprice3" id="transportprice3" class="rounded"></td>
</tr>
</table>

テーブルのチェックボックスごとにアラートが入力されますが、入力は入力されません。私はそれが私のrow.find.

アドバイスをいただければ幸いです、ありがとう

アップデート

現在の構文:

 function populatetransportprice() {
$("table.authors-list").find('input[type="checkbox"][name^="treated"]:checked').each(function () {
 $(this).find('input[name^="transportprice"]').val(treatedtransportcostperton.toFixed(2));
$(this).next('input[name^="transportprice"]').val(treatedtransportcostperton.toFixed(2));
});    
}
4

2 に答える 2

1

「行」はどこにも定義されていません。

    $("table.authors-list").find('input[type="checkbox"][name^="treated"]:checked').each(function () {
        alert(treatedtransportcostperton);
//Try $(this) instead of row. Here 'this' implies each and every element in the loop and then it finds within the element. I think the following code might help,
     $(this).find('input[name^="transportprice"]').val(treatedtransportcostperton.toFixed(2));
$(this).next('input[name^="transportprice"]').val(treatedtransportcostperton.toFixed(2));
//the above is an assumption. Post your HTML
    });   
于 2013-06-10T10:45:12.520 に答える
1

これが影響するマークアップも確認せずに正確な回答を提供することは非常に困難です。

しかし、あなたが私たちに与えてくれた限られた詳細から、これが機能しない理由はあなたのrow変数にあると思います.

これがどのように設定されているかを示す残りのコードはありませんが、row適切に設定されていないか、あなたが考えている要素を参照していないのではないかと思います。

最善の策は、入力に関連する行を確実にターゲットにできるように設定rowすることです。each

何かのようなもの:

function populatetransportprice() {
// iterate through the "checked" checkboxes
$("table.authors-list").find('input[type="checkbox"][name^="treated"]:checked').each(function () {
    var row = $(this).closest('tr'),
        priceInput = row.find('input[name^="transportprice"]');

    alert(treatedtransportcostperton);
    priceInput.val(treatedtransportcostperton.toFixed(2));
}); 

これは、「行」が実際に table-row であることを前提としていますtr

于 2013-06-10T10:46:40.660 に答える