0

わかりました、次のようなチェックボックスがあるとします:

<input type="checkbox" value="1" class="discount_select" name="select[101132]">

...そして、次のような 3 つのテキスト フィールド:

<input type="text" name="start[101132]">
<input type="text" name="end[101132]">
<input type="text" name="discount[101132]">

チェックボックスがオンになっている場合にテキストフィールドの値を更新するコードを現在実行していますが、すべてのIDが異なるため、正しいフィールドをターゲットにできるかどうか、またはどのようにターゲットにできるかわかりません。

だから私は基本的にチェックボックスをループするこのコードを持っていますが、正しいテキストフィールドを更新する方法がわかりません:

// Get values
var discount = $('#apply_discount').val();
var start = $('#apply_start_date').val();
var end = $('#apply_end_date').val();

$('.discount_select:checked').each(function() {

  // How can I target the correct fields/ID's here?

});
4

2 に答える 2

0
Change the name and ids of your fields to make it simpler

<input type="checkbox" value="1" class="discount_select" id="101132" name="select_101132">

<input type="text" name="start_101132">
<input type="text" name="end_101132">
<input type="text" name="discount_101132">

Then:

    var discount = $('#apply_discount').val();
    var start = $('#apply_start_date').val();
    var end = $('#apply_end_date').val();

$('.discount_select:checked').each(function() {
    var select_id = this.attr("id");
    $('[name=start_'+select_id+']').val(start);
    $('[name=end_'+select_id+']').val(end);
    $('[name=discount_'+select_id+']').val(discount);
});
于 2013-08-14T18:34:55.287 に答える