定时器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function fun(name,age){
alert("okokok");
alert(name+age);
alert(tid);
clearTimeout(tid);
};
var tid = setTimeout(fun,500,'szw',18) ;
</script>
</head>
<body>
</body>
</html>
循环调用的定时器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function fshowInfo(name, age){
alert("我是"+name+'年龄是'+age);
};
var inId = setInterval(fshowInfo,2000,'lisi',18);
function fStop(){
clearInterval(inId);
alert("恭喜你停止成功");
}
</script>
<style>
.greencolor{
background-color: chartreuse;
}
</style>
</head>
<body>
<input type="button" value="stop" onclick="fStop();" class="greencolor">
</body>
</html>