用js写了一个秒表程序,不走。。。。火狐调试报错SyntaxError: missing ; before statement
<!doctypehtml><html><head><title>newdocument</title><metahttp-equiv="content-type"con...
<!doctype html>
<html>
<head>
<title> new document </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<style>
#stop{display:none}
</style>
</head>
<body>
<input type="test" id="inp" value=0></br>
<button id="start">开始</button>
<button id="stop">结束</button>
<script>
var start=document.getElementById['start']
var stop=document.getElementById['stop']
var inp=document.getElementById['inp']
i=0;
function write(){
i+=1;
inp.value=i;
}
start.onclick function(){
t=setInterval(write,1000);
stop.style.display="block";//显示出来
this.style.display="none";//隐藏
}
stop.onclick=function(){
clearInterval(t);//清除
start.style.display="block";
this.style.display="none";
i=0;//归零
}
</script>
</body>
</html> 展开
<html>
<head>
<title> new document </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<style>
#stop{display:none}
</style>
</head>
<body>
<input type="test" id="inp" value=0></br>
<button id="start">开始</button>
<button id="stop">结束</button>
<script>
var start=document.getElementById['start']
var stop=document.getElementById['stop']
var inp=document.getElementById['inp']
i=0;
function write(){
i+=1;
inp.value=i;
}
start.onclick function(){
t=setInterval(write,1000);
stop.style.display="block";//显示出来
this.style.display="none";//隐藏
}
stop.onclick=function(){
clearInterval(t);//清除
start.style.display="block";
this.style.display="none";
i=0;//归零
}
</script>
</body>
</html> 展开
1个回答
展开全部
start.onclick后面缺一个=
另外document.getElementById['start']不对,应该是document.getElementById('start')
正确如下:
<!doctype html>
<html>
<head>
<title> new document </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<style>
#stop{display:none}
</style>
</head>
<body>
<input type="test" id="inp" value=0></br>
<button id="start">开始</button>
<button id="stop">结束</button>
<script>
var start=document.getElementById('start');
var stop=document.getElementById('stop');
var inp=document.getElementById('inp');
var i=0,t;
function write(){
i+=1;
inp.value=i;
}
start.onclick = function(){
t=setInterval(write,1000);
stop.style.display="block";//显示出来
this.style.display="none";//隐藏
};
stop.onclick=function(){
clearInterval(t);//清除
start.style.display="block";
this.style.display="none";
i=0;//归零
};
</script>
</body>
</html>
另外document.getElementById['start']不对,应该是document.getElementById('start')
正确如下:
<!doctype html>
<html>
<head>
<title> new document </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<style>
#stop{display:none}
</style>
</head>
<body>
<input type="test" id="inp" value=0></br>
<button id="start">开始</button>
<button id="stop">结束</button>
<script>
var start=document.getElementById('start');
var stop=document.getElementById('stop');
var inp=document.getElementById('inp');
var i=0,t;
function write(){
i+=1;
inp.value=i;
}
start.onclick = function(){
t=setInterval(write,1000);
stop.style.display="block";//显示出来
this.style.display="none";//隐藏
};
stop.onclick=function(){
clearInterval(t);//清除
start.style.display="block";
this.style.display="none";
i=0;//归零
};
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询