点系统-localStorage
我正在尝试创建一个点系统,该系统将在某些点之后执行不同的操作,这是我的 JS:
if (localStorage.points222){
localStorage.points222=Number(localStorage.points222) +5;
}
else{
localStorage.points222=0;
}
if(localStorage.points222 > 35){
$('#hi').show();
}
else{
$('#hi').hide();
}
document.write("Points: " + localStorage.points222 + "");
然后我有要在 35 点后淡入的 HTML:
<div id="hi" style="display:none;">30!</div>
问题是 IF:
if(localStorage.points222 > 35){
$('#hi').show();
}
else{
$('#hi').hide();
}
不起作用...
仅这有效:
if(localStorage.points222!==35){
$('#hi').show();
}
else{
$('#hi').hide();
}
但我不希望 #hi 只在 35 岁显示,我也需要它从 35 岁及以上显示
I'm trying to create a point system that will do different actions after certain points this is my JS:
if (localStorage.points222){
localStorage.points222=Number(localStorage.points222) +5;
}
else{
localStorage.points222=0;
}
if(localStorage.points222 > 35){
$('#hi').show();
}
else{
$('#hi').hide();
}
document.write("Points: " + localStorage.points222 + "");
Then I have the HTML that I want to fadeIn after 35 points:
<div id="hi" style="display:none;">30!</div>
The problem is that the IF:
if(localStorage.points222 > 35){
$('#hi').show();
}
else{
$('#hi').hide();
}
Is not working...
Only this works:
if(localStorage.points222!==35){
$('#hi').show();
}
else{
$('#hi').hide();
}
But I don't want #hi to only show at 35 I need it too show from 35 and Up
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我敢打赌问题是本地存储以字符串形式返回,但您将其视为数字。你需要
I bet the problem is that the local storage is coming back as a string, but you're treating it like a number. You need