본문 바로가기

Javascript

함수들 - alert() prompt() confirm()

alert()

아래에 코드가 있어요!

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function a(){
            alert("클릭하셨군요!");
        }
    </script>
</head>
<body>
    <button onclick="a()">클릭</button>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

prompt("메시지", "기본값 입력")  

사용자로부터 문자열을 입력 받아 리턴

confirm()

 

아래에 코드가 있어요!

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function a(){
            name = prompt("이름을 입력하세요","");
            document.writeln(name);
            ok = confirm("결제할까요?");
            if(ok){
                document.writeln("결제 OK");
            }else{
                document.writeln("결제 CANCLE");
            }
        }
    </script>
</head>
<body>
    <button onclick="a()">클릭</button>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs