웹브라우저 JavaScript

사용자와 커뮤니케이션 하기

HTML은 form을 통해서 사용자와 커뮤니케이션할 수 있는 기능을 제공한다. 자바스크립트에는 사용자와 정보를 주고 받을 수 있는 간편한 수단을 제공한다. 

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

<!DOCTYPE html>
<html>
    <body>
		<input type="button" value="prompt" onclick="func_prompt()" />
		<script>
			function func_prompt(){
				if(prompt('id?') === 'egoing'){
					alert('welcome');
				} else {
					alert('fail');
				}
			}
		</script>
	</body>
</html>

 

댓글

댓글 본문