我有一个电子商务网站,对于同一件商品有多个价格。我正在尝试设置一个脚本,如果页面上存在较低价格,则隐藏一个价格。
<table>
<tbody>
<tr>
<td>
<font>
<div class="product_listprice">199.99</div>
</font>
<font>
<div class="product_productprice">179.99</div>
</font>
<b>
<div class="product_saleprice">159.99</div>
</b>
<font>
<div class="product_discountprice">139.99</div>
</font>
</td>
</tr>
</tbody>
</table>
基本上我需要一个脚本,如果页面中存在.product_saleprice,则隐藏.product_productprice,如果存在.product_discountprice,则同时隐藏.product_saleprice和.product_productprice。
以下是我通过谷歌搜索找到的代码:
<script type="text/javascript">
$(document).ready(function(){
if ( $(".product_discountprice").size() )
$(".product_saleprice, .product_productprice").hide();
});
});
</script>
然而,它似乎并没有起作用。有什么想法吗?我是一个 jQuery 新手,所以肯定有更好的方法……
.size()
改为.length
。 - tymeJV