<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var ti=self.setInterval("putclock()",50);
function putclock(){
var t = new Date();
document.getElementById("clock").value=t;
}
</script>
<form>
<button onclick="ti=window.clearInterval(ti)">stop Interval</button>
</form>
</body>
</html>
为什么这样按钮会没有用呢,而button用以下的方法就可以呢
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var ti=self.setInterval("putclock()",50);
function putclock(){
var t = new Date();
document.getElementById("clock").value=t;
}
</script>
<form>
<input type="button" value="stop Interval" onclick="ti=window.clearInterval(ti)" />
</form>
</body>
</html>