Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何JQuery对输入值求和,然后与价格相乘_Jquery - Fatal编程技术网

如何JQuery对输入值求和,然后与价格相乘

如何JQuery对输入值求和,然后与价格相乘,jquery,Jquery,目前正在shopify上工作,这是我正在处理的链接 当一些数量输入到输入框中,但无法计算出来时,我试图在表中显示总金额 请帮忙 这是我的密码 HTML <table> <thead style="background:#ccc;" > <tr> <th>Color</th> <th>Item #</th> <t

目前正在shopify上工作,这是我正在处理的链接

当一些数量输入到输入框中,但无法计算出来时,我试图在表中显示总金额

请帮忙

这是我的密码

HTML

<table>
    <thead style="background:#ccc;" >
        <tr>
            <th>Color</th>
            <th>Item #</th>
            <th>Pack</th>
            <th>Pack Price</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
{% for variant in product.variants %}
    {% if variant.available %}
        <tr class="{% cycle 'pure-table-odd', '' %}">
            <td>
                <a href="{{ variant.url | collection }}" >
                <center><img src="{{ variant.image | default: product.featured_image | img_url: 'small' }}" alt="{{ variant.title | escape }}" style="width:50px;" /></center>
                </a>
                <center><div>{{ variant.title }}</div></center>
            </td>
            <td>
                <a href="{{ variant.url | collection }}">
                <center>{{ variant.sku }}</center>
                </a>
            </td>
            <td>
                <center><div>
        {% if settings.show-quantity %}
                <input min="0" {% unless variant.inventory_management == blank or variant.inventory_policy == 'continue' %} max="{{ variant.inventory_quantity }}" {% endunless %} type="text" id="quantity" class="quantity addnumber" name="updates[{{ variant.id }}]" value="0" tabindex="1" />
        {% endif %}
                </div></center>  
            </td>
            <td>
                <center>{{ variant.price | money }}</center>
            </td>
        </tr>
    {% endif %}
{% endfor %}
    </tbody>
    <tfoot style="background:#ccc;">
        <tr>
            <td><center>&nbsp;</center></td>
            <td><center>Total</center></td>
            <td><center><input type='text' id='totaladdnumber' class="quantity" disabled /></center></td>
            <td><center><input type='text' id='totaladdprice' class="quantity" disabled /></center></td>
            <td><center>&nbsp;</center></td>
        </tr>
    </tfoot>
</table>

price
class,或
addnumber
?#totaladdprice。这是你误解的。注释中说“我们使用jqueryeach()循环遍历所有带有'price'类的文本框”,但紧跟其后的代码是
$('.addnumber')。每个(…)
!我很抱歉。。不太擅长jquery,也不理解您的评论。@JonKim他的意思是您在HTML中的什么地方放置了这些元素:
price
类,或
addnumber
?\35; totaladdprice。这是你误解的。注释中说“我们使用jqueryeach()循环遍历所有带有'price'类的文本框”,但紧跟其后的代码是
$('.addnumber')。每个(…)
!我很抱歉。。不太擅长jquery,也不理解您的注释。@JonKim他的意思是您在HTML中的什么位置放置了这些元素:
$('.addnumber').keyup(function () {

    // initialize the sum (total price) to zero
    var sum = 0;

    // we use jQuery each() to loop through all the textbox with 'price' class
    // and compute the sum for each loop
    $('.addnumber').each(function() {
        sum += Number($(this).val());
    });

    // set the computed value to 'totalPrice' textbox
    $('#totaladdnumber').val(sum);
});