【发布时间】:2012-09-08 22:23:26
【问题描述】:
嗨
我已经尝试解决这个问题一段时间了,我认为我做的一切都是正确的,但无法让它发挥作用。欢迎任何和所有建议或想法。
我试图在外部 css 样式表上将显示属性从 :none 更改为 :block ,这取决于使用 jQuery 的 localstorage 键的值是否等于 null。
CSS
#cart-totals div.greysp1{
display:none;
border-bottom: 1px solid #ccc;
padding: 3px 0;margin: 0 0 0 20px;
overflow: hidden;
text-align:left;
line-height:18px;
color:#888;}
Javascript/jQuery
if(localStorage.getItem('userScribble')==null){
$("#cart-totals div.greysp1").css("display","block");
console.log("null");
}else{
console.log("Not null")
}
HTML
<div id="cart-totals" >
<div class="cart-totals-content">
<div class="greysp1">
<div class="fL">Merchandise Subtotal:</div>
<div class="fR" id="MerchSubTotal"></div>
</div>
</div>
</div>
有什么想法吗?
我还没有找到任何其他的例子。如果你知道任何让我知道
【问题讨论】:
-
问题出在哪里? jsfiddle.net/C68np/2
-
我认为您可能在这里颠倒了逻辑-如果 localStorage 变量存在或隐藏它,您是要显示元素吗?因为您的代码在 yckarts jsFiddle 中看起来完全一样,如果 LS 变量存在,则实际上隐藏了该元素。
标签: jquery css html local-storage