javascript - jQuery 在将商品添加到购物车时显示 div,而不是之前

标签 javascript jquery html cart webshop

我需要查看一个 div,其中显示您需要购买多少才能在网上商店获得免费送货。

html 看起来像这样:

<div class="l-shopgetmore panel-success">Køb for yderligere DKK 1000.00 og få fragtfri levering.</div>

商店底部有:

<div class="frifragt" style="display: none;">1000</div>
<div class="priceInCart" style="display: none;">0</div>

“priceInCart”中的 0 实际上是一段代码,用于检查购物车中是否有商品并在此处显示 id。在这种情况下,购物车是空的。

CSS:

.l-shopgetmore {
    font-size: 21px;
    text-align: center;
    min-height: 60px;
    padding: 15px 0px;
}


.panel-success {
    background-color: #CAEEF7;
    border-color: #08BFED;
    color: #08BFED;
}

所以我的 jQuery 代码如下所示。

jQuery(document).ready(function(j) {

    var start   = 999,
    getFirstNum = jQuery('.frifragt').text(),
    getSecNum   = jQuery('.priceInCart').text(),
    diff        = Number(getFirstNum) - Number(getSecNum),
    getDiscont  = jQuery('.priceInCart').text()

var getAmount = jQuery('.priceInCart').text();

if(getAmount != '0') {

    if(start > getDiscont) {
        jQuery('.l-shopgetmore').html('K&oslash;b for yderligere DKK ' + diff.toFixed(2) + ' og f&aring; fragtfri levering.');
    } else {
        jQuery('.l-shopgetmore').hide();
    }
} 
});

最后一行

jQuery('.l-shopgetmore').hide();

不工作。

只有当有人将东西放入购物车时,我才需要 jQuery 来显示带有“.l-shopgetmore”类的 div。

最佳答案

jQuery(document).ready(function(j) {
    var frifragt = jQuery('.frifragt');
    var priceInCart = jQuery('.priceInCart');
    var diff = Number(frifragt.text()) - Number(priceInCart.text());
    jQuery('.l-shopgetmore').html('K&oslash;b for yderligere DKK ' + diff.toFixed(2) + ' og f&aring; fragtfri levering.');
    jQuery('.l-shopgetmore').hide();
     setInterval(function(){
       if(jQuery('.priceInCart').text() > 0 || jQuery('.priceInCart').text() < 1000)
          jQuery('.l-shopgetmore').show();
       else
          jQuery('.l-shopgetmore').hide();
     }, '600');


});

关于javascript - jQuery 在将商品添加到购物车时显示 div,而不是之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27980420/

相关文章:

javascript - 使用 Cytoscape.js 添加边缘标签

javascript - javascript 和 css 中的 TreeView 菜单?

javascript - 我的联系表单提交按钮不起作用

html - TextArea 背景图像消失在滚动条后面 - html 5

javascript - leaflet.js 显示空 map : Uncaught Error: Invalid LatLng object: (NaN, NaN)

javascript - 属性列表后缺少 jquery 验证 }

javascript - SAPUI5:禁用富文本编辑器后,仍然可以从word/web粘贴内容

javascript - 如何克服 "Error calling method on NPObject"并 Play() a SWF?

jquery - Bootstrap 3 旋转木马 : CSS3 slider transitions don't work in older IE -- what to do?

javascript - 使用 Apps Script 操作 HtmlOutput 中的 html 内容