반응형

자바스크립트 개발 환경 Microsoft Visual Studio 2015 버전 HTML 기능 및 Chrome을 이용하고 있습니다.






1. setTimeout(id(or function), time)


time 이후에 id 또는 function에 해당하는 함수를 한 번 실행




2. setInterval(id(or fuction), time)


time 주기를 가지며 id 또는 function에 해당하는 함수를 계속 실행




3. clearTimeout(id)


setTimeout을 중지 시켜준다.




4. clearInterval(id)


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
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
    <title>test title</title>
    <script>
 
        var num = prompt('번호를 입력하세요\n1. setTimeout 함수 써보기\n2. setInterval 함수 써보기\n3. clearTimeout 함수 써보기\n4. clearInterval 함수 써보기');
     
        var func = function () {
            location.href = "http://www.crocus.co.kr";
        }
 
        switch(parseInt(num))
        {
            case 1:
               
                /* setTimeout :: 일정시간 후 함수를 한 번 실행 */
                setTimeout(func, 3000);
                break;
            case 2:
                /* setInterval :: 일정시간 마다 함수를 실행 */
                setInterval(function () { alert('hello world') }, 3000);
                break;
 
            case 3:
                /* clearTimeout :: setTimeout을 중지 */
                var id = setTimeout(func, 3000);
                clearTimeout(id);
                break;
            
            case 4:
                /* clearInterval :: setInterval을 중지 */
                var id = setInterval(function () { alert('hello world') }, 3000);
                clearInterval(id);
                break;
        }
        
 
    </script>
</head>
 
</html>
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus



클릭하시면 결과 화면을 확인 할 수 있습니다.






















반응형