簡體   English   中英

如何<span>在jQuery中</span>更新<span>(Shopify Quickview功能)</span>

[英]How to update a <span> in jQuery (Shopify Quickview feature)

我想在Shopify的Quickview功能中添加基本價格,但是我無法使用jquery使一切正常。 我想根據productPrice計算basePase。 問題是,該計算未在HTML中顯示。 看來,我缺少了一些東西。 仍然是空的。 在另一個上下文(Shopify Liquid Code)中,此修改非常簡單。 在這里似乎更復雜。 有沒有人對此有想法/解決方案? 謝謝你的幫助!

  Shopify.doNotTriggerClickOnThumb = false; var selectCallbackQuickview = function(variant, selector) { var productItem = jQuery('.quick-view .product-item'); addToCart = productItem.find('.add-to-cart-btn'), productPrice = productItem.find('.price'), comparePrice = productItem.find('.compare-price'), basePrice = productItem.find('.base-price'), totalPrice = productItem.find('.total-price span'); // Regardless of stock, update the product price productPrice.html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}")); // Also update and show the product's compare price if necessary if ( variant.compare_at_price > variant.price ) { comparePrice .html(Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}")) .show(); productPrice.addClass('on-sale'); } else { comparePrice.hide(); productPrice.removeClass('on-sale'); } BASEPRICE IS CALCULATED HERE: if ( productPrice > 20 ){ if ( productPrice > 90) { basePrice = productPrice / 75 / 12 * 100; } basePrice = productPrice / 75 / 6 * 100; else { basePrice = productPrice / 75 * 100; } /*recaculate total price*/ //try pattern one before pattern 2 var regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g; var unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex); if (!unitPriceTextMatch) { regex = /([0-9]+[.|,][0-9]+)/g; unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex); } if (unitPriceTextMatch) { var unitPriceText = unitPriceTextMatch[0]; var unitPrice = unitPriceText.replace(/[.|,]/g,''); var quantity = parseInt(jQuery('.quick-view input[name=quantity]').val()); var totalPrice = unitPrice * quantity; var totalPriceText = Shopify.formatMoney(totalPrice, window.money_format); regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g; if (!totalPriceText.match(regex)) { regex = /([0-9]+[.|,][0-9]+)/g; } totalPriceText = totalPriceText.match(regex)[0]; var regInput = new RegExp(unitPriceText, "g"); var totalPriceHtml = jQuery('.quick-view .price').html().replace(regInput ,totalPriceText); jQuery('.quick-view .total-price span').html(totalPriceHtml); } /*end of price calculation*/ }; 
  <div class="prices"> <span class="compare-price"></span> <span class="price"></span> <span class="base-price">BASEPRICE SHOULD BE SEEN HERE</span> </div> 

您應該能夠:

$('.base-price').text(basePrice);

這將找到具有類名“ base-price ”的元素,並將文本設置為basePrice的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM