首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >重力在每个产品数量jquery旁边形成小计

重力在每个产品数量jquery旁边形成小计
EN

Stack Overflow用户
提问于 2012-08-14 05:32:41
回答 1查看 1.7K关注 0票数 1

我正在使用Gravity产品字段创建一个订单类型系统。

我尝试计算每个产品的小计(成本*数量),并通过jQuery将其显示在数量旁边。

这是我的jQuery:

代码语言:javascript
运行
复制
<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的一个片段:

代码语言:javascript
运行
复制
<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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-14 05:38:01

您的next()方法选择类为.product_subtotal的所有div标记,因为您在调用next()方法之前选择了页面上的所有.ginput_quantit输入,该方法选择了类为.product_subtotal的所有div标记,请尝试如下所示:

代码语言:javascript
运行
复制
$('.ginput_quantity').keypress( function( ) {
    $x = $(this); // just this input element
    $x.next('div.product_subtotal').html( this.value ); 
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11942648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档