29 lines
707 B
HTML
29 lines
707 B
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript">
|
|
//setInterval
|
|
//每间隔多久就执行一次函数
|
|
//参数 1函数
|
|
//参数 2时间(毫秒)
|
|
// window.setInterval(function(){
|
|
// alert('哈哈,卡住了')//alert具有阻塞性
|
|
// },1000)
|
|
//返回值就是定时器的Id
|
|
var timerId = setInterval(function(){
|
|
console.log('hahaha')
|
|
},10)
|
|
window.onload = function(){
|
|
document.getElementById('btn').onclick = function(){
|
|
//clearInterval(定时器的id)
|
|
window.clearInterval(timerId)
|
|
}
|
|
}
|
|
</script>
|
|
<input type="button" name="" value="停止定时器" id="btn">
|
|
</body>
|
|
</html> |