타이머 1
특정 기간 후에 프로그램이 실행되도록 지정하는 데 사용됩니다.
settimeout () :
형식 : [타이머 개체 이름 =] settimeout ( "<표현>", 밀리 초)
기능 : <표현> 한 번 실행하십시오.
예:
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<title> timer1.html </title>
<meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3">
<meta http-equiv = "description"content = "이것은 내 페이지입니다">
<meta http-equiv = "content-type"content = "text/html; charset = utf-8">
<!-<link rel = "스타일 시트"유형 = "text/css"href = "./ styles.css">->
<script type = "text/javaScript">
함수 수 ()
{
settimeout ( "alert ( 'execution success!')", 7000);
}
</스크립트>
</head>
<body>
<input type = "button"value = "click me"onclick = "count ();">
</body>
</html>
타이머 2
특정 시간 간격으로 표현식을 반복적으로 실행합니다.
setInterval () :
형식 : [타이머 개체 이름 =] setInterval ( "<표현>", 밀리 초)
기능 : 창과 프레임이 닫히거나 ClearInterval이 실행될 때까지 <표현>을 반복하십시오.
ClearInterVal () :
형식 : ClearInterVal (타이머 개체 이름)
기능 : 타이머 종료
예:
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<title> timer2.html </title>
<meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3">
<meta http-equiv = "description"content = "이것은 내 페이지입니다">
<meta http-equiv = "content-type"content = "text/html; charset = utf-8">
<!-<link rel = "스타일 시트"유형 = "text/css"href = "./ styles.css">->
<script type = "text/javaScript">
var sec = 0;
var timer = setInterVal ( "count ();", 1000); // 페이지가로드 될 때 시간이 시작됩니다.
함수 수 ()
{
document.getElementById ( "num"). innerHtml = sec ++;
}
함수 stopCount ()
{
ClearInterval (타이머); // 타이머 실행 중지
}
</스크립트>
</head>
<body>
<font color = "red"id = "num"> 0 </font>
<input type = "button"value = "stop"onclick = "stopCount ();">
</body>
</html>
위는이 기사의 전체 내용입니다. 나는 당신이 그것을 좋아하기를 바랍니다