반응형
alert
* 경고창, 사용자에게 정보를 제공하거나 디버깅의 용도로 많이 쓴다.
<!DOCTYPE html> <html> <body> <input type="button" value="alert" onclick="alert('hello world');" /> </body> </html>
confirm
* 확인을 누르면 true, 취소를 누르면 false를 반환한다.
<!DOCTYPE html>
<html>
<body>
<input type="button" value="confirm" onclick="func_confirm()" />
<script>
function func_confirm(){
if(confirm('ok?')){
alert('ok');
} else {
alert('cancel');
}
}
</script>
</body>
</html>
prompt
* 사용자가 입력한 값을 JavaScript가 얻어 낼 수 있는 것.
<!DOCTYPE html>
<html>
<body>
<input type="button" value="prompt" onclick="func_prompt()" />
<script>
function func_prompt(){
if(prompt('id? (write hong') === 'hong'){
alert('welcome');
} else {
alert('fail');
}
}
</script>
</body>
</html>
반응형
'WEB > JavaScript' 카테고리의 다른 글
| BOM : Navigator 객체 (0) | 2016.10.14 |
|---|---|
| BOM : Location 객체 (0) | 2016.10.14 |
| Object Model (0) | 2016.10.14 |
| 복제, 참조 (0) | 2016.10.13 |
| 원시 데이터 타입과 레퍼 객체 (0) | 2016.10.13 |