我有这个跨度:jQuery的隐藏的div,如果值小于
<span class="price">£260.00</span>
和另一另一个
<span class="price">£90.00</span>
我需要隐藏低于当值的DIV从跨度小于£100.00。
<div id="shipping"></div>
任何人都可以帮助我解决这个问题。我需要知道如何使用jQuery来做到这一点。
我有这个跨度:jQuery的隐藏的div,如果值小于
<span class="price">£260.00</span>
和另一另一个
<span class="price">£90.00</span>
我需要隐藏低于当值的DIV从跨度小于£100.00。
<div id="shipping"></div>
任何人都可以帮助我解决这个问题。我需要知道如何使用jQuery来做到这一点。
这应该工作:
var price = $(".price").text().replace("£","");
if(price < 100)
{
$("#shipping").hide();
}else{
$("#shipping").show();
}
希望它能帮助。
这应该工作太:
jQuery(function($) {
var price = $('span.price'),
// get float number from span.text() excluding other characters than digits and dot
priceValue = Number(price.text().replace(/[^0-9\.]+/g,"")),
priceLimit = 100,
shipping = $("#shipping");
shipping.show(); // by default shipping show
if (priceValue > priceLimit) {
// other case shipping hide
shipping.hide();
}
});
是否有可能你的成本数值(不带井号)存储在另一个单独的属性?例如'£260.00'。它会让这个容易。 – Reflection