我在订购表格时无法在线订购产品。我有不同类别的多种产品。例如家具和电力。在家具类别中,我有三个产品input type="number"
,data-price
属性,其中填写了价格(产品从数据库中取出),因此所有内容都将自动填写。
输入值的计算出了什么问题。我在下面有这个片段,它正好显示了这个问题。当您为第一个产品选择1时,它会正确显示25.50,但是当您将数量增加一个时,它的值为2.然后价格显示为76.50 ......这样就出错了。
有人可以帮我解决这个问题,以便计算出正确的金额吗?
提前致谢!
var furnitureTotal = 0;
$("#furnituretotal").html(furnitureTotal.toFixed(2));
function getFurnitureProductsTotal(className) {
var furnitureProducts = $('.' + className);
furnitureProducts.each(function() {
var price = parseFloat($(this).attr('data-price'));
var number = $(this).val();
furnitureTotal += price * number;
});
$("#furnitureamount").val(furnitureTotal.toFixed(2));
$("#furnituretotal").html(furnitureTotal.toFixed(2));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product">
<img src="/uploads/products/product-table.jpg" alt="Product image">
<strong>Table</strong><br>
€ 25.50<br>
<input type="number" class="orderinputsfurniture" name="5" data-price="25.50" onchange="getFurnitureProductsTotal('orderinputsfurniture')" value="0" min="0" max="10" />
</div>
<br>
<div class="product">
<img src="/uploads/products/product-1512-individualshelfwidth:100cmdepth:30cm.jpg" alt="Product image">
<strong>1512 - Individual Shelf Width: 100cm Depth: 30cm</strong><br>
€ 20<br>
<input type="number" class="orderinputsfurniture" name="8" data-price="20" onchange="getFurnitureProductsTotal('orderinputsfurniture')" value="0" min="0" max="10" />
</div>
<br><br><br>
<input type="text" id="furnitureamount" name="furnitureamount" value="0">
答案 0 :(得分:3)
每次while True:
driver.get(driver.getCurrentUrl())
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "id_of_element_present_in_all_situation")))
source = driver.page_source
-- check for change --
函数运行时,您只需将furnitureTotal
重置为0
:
getFurnitureProductsTotal
&#13;
var furnitureTotal = 0;
$("#furnituretotal").html(furnitureTotal.toFixed(2));
function getFurnitureProductsTotal(className) {
var furnitureProducts = $('.' + className);
furnitureTotal = 0;
furnitureProducts.each(function() {
var price = parseFloat($(this).attr('data-price'));
var number = $(this).val();
furnitureTotal += price * number;
});
$("#furnitureamount").val(furnitureTotal.toFixed(2));
$("#furnituretotal").html(furnitureTotal.toFixed(2));
}
&#13;