我的这个代码怎么没用
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
function clock(){
var time=new Date();
document.getElementById("clock").value = time;
}
var i=setInterval(clock,100) ;
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="clearInterval(i)" />
</form>
</body>
</html>
提交下,然后刷新下页面就好了...
根本停不下来--!
我直接复制粘贴你的代码,stop可以用啊!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
function clock(){
var time=new Date();
document.getElementById("clock").value = time;
}
var timer =setInterval(clock,100);
function stop(){
clearInterval(timer);
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick ="stop()" />
</form>
</body>
</html>这个代码与之相近 你看了更明白
理解下这个 就没啥问题了
<script type="text/javascript">
function clock(){
var time = new Date();
document.getElementById("clock").value = time;
}
var timer = setInterval(clock, 1000);
var flage = true;
function stopTime() {
flage = !flage;
if(flage == false) {
clearInterval(timer);
document.getElementById("btn").value = "重新开始";
}else {
timer = setInterval(clock, 1000);
document.getElementById("btn").value = "暂停";
}
}
</script>