我生成了如下输入:
<input type="text" id="rfq_ironilbundle_quotes_offer_price_0" name="rfq_ironilbundle_quotes[offer_price][0]" required="required" class="form-control offered-price">
<input type="text" id="rfq_ironilbundle_quotes_offer_price_1" name="rfq_ironilbundle_quotes[offer_price][1]" required="required" class="form-control offered-price">
这些输入可以多于两个。
当用户填写并附加到 div 元素时,我需要计算输入中的所有价格。我怎样才能做到这一点?
最佳答案
这是一个应该可以完成您想要的操作的示例。 http://jsfiddle.net/yvy986nc/
JS 代码片段。
$('input.offered-price').keyup(function(){
var val = 0;
$('input.offered-price').each(function(){
try{
val += parseInt($(this).val(), 10) || 0;
}catch(e){
// just to catch parse int failures
}
});
$('#result').html(val);
});
关于javascript - 使用 jQuery 计算生成的输入整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28773568/