我写的哪里有问题,为什么不能实现效果呢?点击stop按钮不能停止?
是的,应该不是代码问题
我也发现了这个问题,直接写好的代码没能直接起上效果,只有提交以后再刷新打开,才能生效。包括动态时间生成后,你setInterval注释掉,结果还是有动态时间,除非刷新一下网页
<!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>看不到你的代码,你问啥呢?