你好,如果值是0.00..here是我的代码,我想隐藏一个span和div
<span class="price-old"> <%=getCurrentAttribute('item','custitem_sumisho_listprice')%> </span>
<span class="price-new"><%=getCurrentAttribute('item','custitem_sumisho_onlineprice')%> </span>
<div class="save-sale" style="font-size: .8em; padding-top: 4em"><%=getCurrentAttribute('item','custitem_sumisho_totalsave')%></div>在上面的代码中,如果class=的“保存-销售”的div将有0.00的值,那么我想隐藏class=的“价格-旧”,而class=“保存-销售”的.Here getattribute标签将得到项目价格的值。
我尝试过以下jquery,但它不起作用。
<script type="text/javascript" src="/site/js/jquery-1.10.2.min.js"></script>
<script>
$(function () {
if ($(".save-sale").text() == "0.00") {
$(".save-sale").hide();
$(".price-old").hide();
}
});
</script>发布于 2014-10-31 05:52:06
由于您有多个save-sale div,所以可以使用.each()来迭代它们,并检查其值以使save-sale和price-old隐藏起来。
<script type="text/javascript" src="/site/js/jquery-1.10.2.min.js"></script>
<script>
$(function () {
$(".save-sale").each(function(){
if ($(this).text().trim() == "0.00") {
$(this).hide();
$(this).prev(".prod-price").find(".price-old").hide();
}
});
});
</script>发布于 2014-10-31 05:57:12
试试这个:
<script type="text/javascript" src="/site/js/jquery-1.10.2.min.js"></script>
<script>
$(function () {
if ($.trim($(".save-sale").text()) == "0.00") {
$(".save-sale").hide();
$(".price-old").hide();
}
});
</script>对于具有相同类名的多个Div,可以尝试以下方法:
$(function () {
$(".save-sale").each(function (i) {
if ($.trim($(this).text()) == "0.00") {
$(this).closest(".save-sale").hide();
$(this).closest(".price-old").hide();
}
else{
$(this).closest(".save-sale").show();
$(this).closest(".price-old").show();
}
});
});发布于 2014-10-31 06:11:37
您可以使用
$(".class或#id").hide()
或者类似的东西,但使用的css样式
$(".class或#id“).css(”显示“,”无“)
但是,如果您想将其设置为带有类的所有元素,那么显然要使用每个函数:
$(“.class”).each(函数(){ $(this).css('display','none') });
https://stackoverflow.com/questions/26668288
复制相似问题