- window 객체
- window 객체 : html 페이지의 최상단 객체. window 생략 가능
- alert(내용) : 확인 메세지. 리턴값이 없음.
- confirm(내용) : 확인,취소 선택.
확인 선택 : true
취소 선택 : false
- prompt(내용) : 입력란이 존재. 값을 입력받고, 입력받은 값을 리턴
- this.form : 내가 속한 form 객체를 의미
📌 window 객체의 3가지 메세지 창
<!DOCTYPE html>
<!-- src/main/webapp/20220922/javascript3.html -->
<html>
<head>
<meta charset="UTF-8">
<title>window 객체의 3가지 메세지 창</title>
</head>
<body>
<form name="f">
<input type="radio" name="dbox"
onclick="document.f.echo.value=window.alert('alert 메세지 창 호출')">
alert 메세지 창 호출<br>
<input type="radio" name="dbox"
onclick="this.form.echo.value=window.confirm('confirm 메세지 창 호출')">
confirm 메세지 창 호출<br>
<input type="radio" name="dbox"
onclick="this.form.echo.value=window.prompt('prompt 메세지 창 호출')">
prompt 메세지 창 호출<br>
<input type="text" name="echo">
</form>
</body>
</html>
- window 객체의 함수
eval 함수 : 수식 계산 결과 리턴
eval(문자열) : 문자열 수식을 계산 결과 리턴
isNaN : 숫자가 아니니? 숫자가 아닌경우 : true, 숫자인 경우 : false
parseInt : 문자열을 정수 변환
parseInt(문자열, 진수) : 문자열을 정수 변형.
📌
<!DOCTYPE html>
<!-- src/main/webapp/20220922/javascript4.html -->
<html>
<head>
<meta charset="UTF-8">
<title>window 객체의 함수</title>
</head>
<body>
<script type="text/javascript">
let i=2
//eval 함수 : 수식 계산 함수
document.write("eval(3+4*(5-i))="+eval(3+4*(5-i))+"<br>")
document.write("eval(3+4*5)="+eval('3+4*5')+"<br>")
document.write(`3+4*(5-i)=${3+4*(5-i)}<br>`) //ECMA6
document.write("3+4*(5-i)="+`${3+4*(5-i)}` + "<br>") //ECMA6
//isNaN : 숫자가 아니니? 숫자가 아닌경우 : true, 숫자인 경우 : false
document.write("isNaN('한국')="+window.isNaN('한국')+"<br>")
document.write("isNaN('123')="+isNaN('123')+"<br>")
//정수형 <= 문자열
document.write("parseInt('10')="+parseInt('10')+"<br>")
document.write("parseInt('12',8)="+parseInt('12',8)+"<br>")
document.write("parseInt('FF',16)="+parseInt('FF',16)+"<br>")
document.write("parseInt('FF')="+parseInt('FF')+"<br>")
</script>
</body>
</html>
'수업(국비지원) > JavaScript' 카테고리의 다른 글
| [JavaScript] Math 클래스 사용, onchange 이벤트 (0) | 2023.04.18 |
|---|---|
| [JavaScript] prompt 메세지 (0) | 2023.04.18 |
| [JavaScript] name 속성을 이용한 태그 선택, 마우스 이벤트(onmouseover, onmouseout) (0) | 2023.04.18 |
| [JavaScript] 조건문, 반복문 예제(JavaScript 에서 제공하는 내장객체 ) (0) | 2023.04.18 |
| [JavaScript] 기본 자료형(alert, document,console), 변수 선언 (0) | 2023.04.18 |