我正在使用Gravity产品字段创建一个订单类型系统。
我尝试计算每个产品的小计(成本*数量),并通过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字段中输入的值来更新quantity分区。我稍后会担心实际的计算。我的问题是,我不确定如何选择下一个div.product_subtotal,因为$x.next()会选择每个product_subtotal。
发布于 2012-08-14 05:38:01
您的next()方法选择类为.product_subtotal的所有div标记,因为您在调用next()方法之前选择了页面上的所有.ginput_quantit输入,该方法选择了类为.product_subtotal的所有div标记,请尝试如下所示:
$('.ginput_quantity').keypress( function( ) {
$x = $(this); // just this input element
$x.next('div.product_subtotal').html( this.value );
});https://stackoverflow.com/questions/11942648
复制相似问题