根据产品价格显示报价

时间:2015-12-30 18:53:28

标签: javascript jquery business-catalyst

我目前四处寻找一些有吸引力的方式来吸引客户的观点,我偶然会根据每个产品的价格详细说明一条消息。

本主题主要针对Business Catalyst,但有些javascript专家可能会提供帮助。

目标是在小型产品布局上使用液体或一些灵活的 Javascript ,并计算产品价格,如果高于或等于30且显示您为此产品免费送货

我目前正在使用jquery但不工作不知道为什么!?

$('.price').each(function(){
    if(parseInt($(this).val()) > 30) {
   $('#get-free').show();
}
});

<div class="small-product round-corner">
 <div class="im-on-sale-{tag_onsale}">SALE</div>
 <div class="photo">{tag_smallimage}</div>
 <div class="title lato">{tag_name}</div>
<div class="price lato"><!--Price: -->{tag_saleprice}</div>
 <div class="retail-price">{tag_retailprice}</div> 
 <div class="instock">{tag_instock} IN STOCK</div>
<div id="get-free" style="display: none;">FREE SHIPPING FOR THIS PRODUCT</div>
<!--<div class="add-to-cart-small">{tag_addtocart,<img src="/images/ui-pieces/add-to-cart-small.png" width="25" height="25" />}</div>-->
<div class="lato rating-stars"><span class="smallString" style="display: none;">{tag_itemurl_nolink}</span></div>
 <div class="favorite loggedin lato"> {tag_addtofavorites,<div class="grey-link"><img src="/images/ui-pieces/favourites-icon.png" width="15" height="15">  ADD TO FAVORITES</div>, <div class="grey-link"><img src="/images/ui-pieces/close-bt.png" width="15" height="15"> REMOVE FAVORITE}</div>
</div>

非常感谢一些帮助。

由于

3 个答案:

答案 0 :(得分:2)

您应该尝试使用Name: Nexus_5_API_23_x86 CPU/ABI: Google APIs Intel Atom (x86) Target: Google APIs (API level 23) Skin: 1080x1920 SD Card: 200M hw.dPad: no hw.accelerometer: yes hw.device.name: Nexus 5 vm.heapSize: 64 skin.dynamic: no hw.device.manufacturer: Google hw.gps: yes hw.audioInput: yes tag.id: google_apis hw.camera.back: emulated hw.mainKeys: no hw.camera.front: emulated hw.lcd.density: 480 hw.device.hash2: MD5:2fa0e16c8cceb7d385183284107c0c88 hw.ramSize: 1536 hw.trackBall: no hw.battery: yes hw.sdCard: yes tag.display: Google APIs hw.keyboard: yes hw.sensors.proximity: yes disk.dataPartition.size: 200M hw.sensors.orientation: yes avd.ini.encoding: UTF-8 hw.gpu.enabled: yes https://css-tricks.com/snippets/wordpress/include-jquery-in-wordpress-theme/)或.text()代替.html()val()主要用于表单输入字段(http://siliconvalleyindicators.org/data/people/talent-flows-diversity/total-science-engineering-degrees-conferred/

答案 1 :(得分:1)

对div之类的非输入元素使用text()而不是val()。此外,您应该在使用parseInt时使用isNaN测试NaN,尽管在这种情况下,如果价格字段为空,则不会出现所需的效果(显示免费定价)。

if(!isNaN(parseInt($(this).text())) && parseInt($(this).text()) > 30)

这是Fiddle Demo

答案 2 :(得分:0)

感谢Vitorino提供的一段代码,我能够明确指出,但是由于{tag_saleprice}由{tag_saleprice}生成​​的“£”符号,它的真正原因是它没有得到正确的字符串。使用我之前使用的 .replace(/ [^ 0-9。] / g,“”); ,我能够传递清除符号“£”的值,下面是代码对于那些需要的人:

$('.price').each(function() {
var price = $(this).text().replace(/[^0-9\.]/g, "");
   if (parseInt(price) >= 30) {
    $(this).siblings('.get-free').show();
  }
});

Demo

相关问题