我試圖在magento 2.1產品上進行自動價格計算。當我在代碼片段或jsfiddle上測試代碼時,它正常工作,但是當在真正的magento站點上運行時,「mouseup」計算函數的結果將顯示在下一次單擊(或從前一次單擊)上,但在「keyup」上運行良好。有人對此案有任何答案嗎?jQuery,顯示下一次點擊的功能結果
$(document).ready(function(){
$(".control").on("keyup mouseup",function(){
var totale = 0;
$(".quantity-number .qty").each(function() {
var qty = parseFloat($(this).val());
//var price = parseFloat($(".price-wrapper").attr("data-price-amount"));
//var price = parseFloat($(".price").attr("data-price-amount"));
//var price = parseFloat($(".price").text());
var price = parseFloat($('.product-info-main span.price').text().match(/\d+/)[0], 10);
/*
var temp=$(".price").text();
var num = temp.match(/[\d\.]+/g);
if (num != null){
var price = num.toString();
}
*/
totale += qty * price;
totale = qty * price;
});
$(".cal-price").html("฿"+totale.toFixed(2));
});
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div class="product-info-main">
<span class="price-wrapper" data-price-amount="10">
<span class="price">
฿10.00
</span>
<div class="control">
<div class="quantity-number">
<input type="number" name="qty" id="qty" maxlength="12" value="1" title="Quantity" class="input-text qty">
</div>
<span class="cal-price"></span>
</div>
,我更新這樣的代碼:https://jsfiddle.net/l2esforu/x6332ay3/3/ 它的做工精細如舊,但Magento站點沒有顯示出任何結果。 請參閱:http://prntscr.com/ec1acp –