<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var i=setInterval("clock()",1000);
function clock(){
var time=new Date();
document.getElementById("clock").value = time;
var butt=document.getElementById("but");
butt.onclick()=function(i){
clearInterval(i);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" id="but"/>
</form>
</body>
</html>
butt.onclick()=function(){ 多了个括号,不用传参进去---------------- butt.onclick=function(){}
clearInterval(i);
}
onclick=""这样才行。