본문 바로가기

IT Study/Web

[JavaScript] setInterval 기본 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<form name="form1">
전화하는 시간은
<input type="text" size="10" name="formSec">
입니다<br>
전화요금은
<input type="text" size="10" name="formWon">
입니다
</form>
 
<button type="button" onclick="document.bgColor='#ffff00'">배경색 변경</button>
 
<script type="text/javascript">
var myCnt = 1;
 
function func() {
    document.form1.formSec.value = myCnt + "초";
    
    document.form1.formWon.value = ((Math.floor(myCnt/5* 10+ 10+ "원";
    
    myCnt = myCnt + 1;
}
 
setInterval("func()",100);
</script>
</body>
</html>
cs


Delay, sleep과 같은 기능