1

Gravity Forms の製品フィールドを使用して、注文フォーム タイプのシステムを作成しています。

各製品の小計 (コスト * 数量) を計算し、数量の横に jQuery を介して表示しようとしています。

これが私のjQueryです:

<script type="text/javascript">
    $(document).ready(function() {
        $('.gfield_price .ginput_container').append('<div class="product_subtotal">SUBTOTAL</div>');
        $('.ginput_quantity').keypress( function( ) {
            $x = $('.ginput_quantity');
            $x.next('div.product_subtotal').html( this.value );
        });
    });
</script>

ここに私のhtmlのスニペットがあります:

<li id='field_5_12' class='gfield gfield_price gfield_price_5_12 gfield_product_5_12' >
    <label class='gfield_label' for='input_5_12'>500 GPH Bilge Pump 24V</label>
    <div class='ginput_container'>
        <input type='hidden' name='input_12.1' value='500 GPH Bilge Pump 24V' class='gform_hidden' />
        <span class='ginput_product_price_label'>Price:</span>
        <span class='ginput_product_price' id='input_5_12'>$2.99</span>
        <input type='hidden' name='input_12.2' id='ginput_base_price_5_12' class='gform_hidden' value='$2.99'/>
        <span class='ginput_quantity_label'>Quantity:</span>
        <input type='text' name='input_12.3' value='' id='ginput_quantity_5_12' class='ginput_quantity' size='10' tabindex='6'/>
    </div>
</li>

ご覧のとおり、現在、product_subtotal div を数量フィールドに入力された値で更新しようとしています。実際の計算については後で考えます。私の問題は、$x.next() がすべての product_subtotal を選択するため、次の div.product_subtotal だけを選択する方法がわからないことです。

4

1 に答える 1

1

next()クラス のすべての div タグを選択するメソッドを呼び出す前に、ページ上の.product_subtotalすべての入力を選択しているため、メソッドはクラス のすべての div タグを選択します。これを試してください。.ginput_quantitnext().product_subtotal

$('.ginput_quantity').keypress( function( ) {
    $x = $(this); // just this input element
    $x.next('div.product_subtotal').html( this.value ); 
});
于 2012-08-13T21:38:00.520 に答える