我正在尝试使用localStorage告诉我何时值很低。例如:如果localStorage值低于5,那么说你不是那么低。我创建了一个名为“item1”的localStorage变量(可用的数字)和另一个名为“stockr1”的变量(这是item1必须在下面进行的),最后一个名为“stockm1”(当item1变为时,在div中显示的消息)低于stockr1(如果item1< = stockr1则显示stockm1)。
这是代码(localStorage引用在另一页面上设置)
<center>
<body bgcolor="#FFD801"
onload="document.body.style.opacity='1';myFunction(); ">
<div align="center">
<p id="show" ></p>
<script>
function myFunction() {
if(parseInt(localStorage.item1, 10) <= parseInt(localStorage.stokr1, 10))
{
document.getElementById('show').innerHtml = localStorage.stockm1;
// if you use jquery
//$('#controlinwhichyouwanttoshowmessge').html(stockm1);
}
}
</script>
</div>
</body>
</center>
</font>
</html>
答案 0 :(得分:0)
但是,您的问题并没有提供所有信息,但我试图根据您提供的数据了解您应该做些什么
if(parseInt(item1, 10) <= parseInt(stokr1, 10))
{
document.getElementById('element_id_to_show_message').innerHtml = stockm1;
// if you use jquery
//$('#controlinwhichyouwanttoshowmessge').html(stockm1);
}
答案 1 :(得分:0)
当我做的时候它起作用了:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Reminders</title>
</head>
<font face="monospace" size="6" color="#3a3a3a">
<center>
<body bgcolor="#FFD801" onload="document.body.style.opacity='1';myFunction(); ">
<div align="center">
<p id="demo" ></p>
<script>
function myFunction() {
var a = parseInt(localStorage.item1) ;
var b = parseInt(localStorage.stockr1) ;
var n = a <= b;
if (a <= b){
document.getElementById("demo").innerHTML = localStorage.stockm1;
}
}
</script>
</div>
</body>
</center>
</font>
</html>