js Uncaught ReferenceError: sessionStorage is not defined,各位大神求解
<html><headlang="en"><metacharset="UTF-8"><title></title><script>vardid,btn1,btn2,w=n...
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
var did,btn1,btn2,w=null;
window.onload=function(){
did=document.getElementById("did");
btn1=document.getElementById("btn1");
btn2=document.getElementById("btn2");
btn1.onclick=start;
btn2.onclick=stop;
}
function start(){
if(w){
return;
}
w=new Worker("index.js");
w.onmessage=function(e){
did.innerHTML= e.data;
}
}
function stop(){
if(w){
w.terminate();
w=null;
}
}
</script>
</head>
<body>
<div id="did">0</div>
</body>
index.js 如下
var num= 0;
function ems(){
if(sessionStorage.num){
num=sessionStorage.num;
}
num++;
postMessage(num);
sessionStorage.num=num;
setTimeout(ems, 1000);
}
ems(); 展开
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
var did,btn1,btn2,w=null;
window.onload=function(){
did=document.getElementById("did");
btn1=document.getElementById("btn1");
btn2=document.getElementById("btn2");
btn1.onclick=start;
btn2.onclick=stop;
}
function start(){
if(w){
return;
}
w=new Worker("index.js");
w.onmessage=function(e){
did.innerHTML= e.data;
}
}
function stop(){
if(w){
w.terminate();
w=null;
}
}
</script>
</head>
<body>
<div id="did">0</div>
</body>
index.js 如下
var num= 0;
function ems(){
if(sessionStorage.num){
num=sessionStorage.num;
}
num++;
postMessage(num);
sessionStorage.num=num;
setTimeout(ems, 1000);
}
ems(); 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询