我正在处理一个购物车,我的客户希望它在空的时候有一个背景,而当它有物品时有另一个背景。所以这就是我得到的标记:
<a href="#" id="shopping-cart" data-count="0" class="trigger cart">
<span>
</span>
</a>
数据计数的更改正在服务器端处理并通过 php 更新我的问题是我不知道如何让 jquery 读取数据计数并制作 if 语句以便读取
if data-count= 0 then add .empty
else data-count > 0 then add .full
另外,我不确定我是否应该使用.addClass
或.toggleClass
从空到满,对不起,到目前为止,我所有编写 jquery 的尝试都失败了,所有正在度假的处理程序,所以我将不胜感激所有的帮助。
决定更改正在使用的插件,现在我尝试在新插件上复制它,但似乎无法绕开它来实现它,可用的新代码如下所示:
<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"
title="<?php _e('View your shopping cart', 'woothemes'); ?>">
<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>