타이머 및 타이머 지우기

1747 단어
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> setTimeout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="  http://www.itbool.com" />
<script>
function bang(){
document.getElementsByTagName('img')[0].src="off.png";
}
// 
setTimeout('bang()',3000);
</script>
</head>
    <body>
     <h1> , </h1>
     <img src="on.png" alt="" />
    </body>

</html>
/*****************************************/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> setTimeout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="  http://www.itbool.com" />
<script>
function bang(){
var inp=document.getElementsByName('on')[0];
var time=inp.value-1;
inp.value=time;
if(time==0){
document.getElementsByTagName('img')[0].src="off.png";
//clear 
clearInterval(clock);
}
}
// 
var clock=setInterval('bang()',1000);
</script>
</head>
    <body>
     <h1> , </h1>
     <input type="button" value="5" name="on"/>
     <img src="on.png" alt="" />
    </body>

</html>

좋은 웹페이지 즐겨찾기