1.
예) window.document.form1.id.value="lee"
코드설명: 현제 브라우저의 창에 존재하는 문서 내용중 "form1" 안에 "id" 객체의 값은 "lee"이다.
주요객체
window : 윈도우마다 하나씩 존재하는 객체로서 윈도우 내에 존재하는 모든객체의 상위 객체이다.
frame:프레임마다 존재하는 객체<frame>태그에 의해 정의 된다.
document : html 페이지마다 존재하는 객체, html문서에 대한 정보를 가진다.
location : 현재 로드된 html페이지의 url에 대한 정보
history : 현재 사용자가 방문하였던 url 들이 리스트를 우지하는 객체이다.
form : 폼에대한 정보를 표헌하는 객체로서 <form>태그당 하나의 객체
계층구조에 따라서 자바 스크립트에 접근
예
<html>
<head>
<title>4-1 계층구조로 객체사용 </title>
</head>
<body>
<form name="f">
<input type ="text" name ="a" value ="나는 자바 스크립트!">
<input type ="text" name ="b" ><p>
<input type ="button" value="복사" onClick ="document.f.b.value = document.f.a.value"><br>
-->******** documet.f.b.value 와 this.form.b.value와 같다. *******
<input type ="button" value="지우기" onClick="this.form.b.value=''" ><p>
</form>
</body>
</html>
****이벤트 ****
이벤트 처리이벤트
abort Onabort : 이미지를 읽는 중에 중지했을때 발생
blur OnBlur :입력양식 필드에서 포커스를 일어 버렸을대 발생(커서가 깜빡일때)
changge OnChange: 입력양식 필드에서 값이 바뀌었을때 발생
click OnClick : 입력양식필드에서 마ㅅ우스를 눌렀을때 발생
dblclick OndblClick : 마우스를 두 번 눌렀을때 발생
dragdrop OnDragDrop: 마우스를 클릭한 상태에서 드래그 했을때 발생
error OnError : 문서나 이미지를 읽는 중에 중지 했을때 발생
focus OnFocus : 입력양식 필드에 포커스가 위치할때 발생
keydown OnKeyDown : 키를 눌렀을때 발생
keypress OnKeyPress : 키를 눌렀다가 놓았을대 발생
keyup OnKeyUp : 키를 놓았을때
load OnLoad :브라우저의 문서를 읽어올때 발생
mousedown OnMouseDown : 마우스 버튼을 눌렀을때 발생
mousemove OnMouseMove : 마우스 위치를 옮겼을때 발생
mouseout OnMouseOut : 마우스가 링크나 영역안에 있다가 벗어났을때 발생
mouseover OnMouseOver : 링크위로 마우스가 위치할때 발생
mouseup OnMouseUp : 마우스를 놓았을때 발생
move OnMove : 프레임이나 우인도를 이동했을 경우에 발생
reset OnReset : 입력양식을 다시 초기화 시켰을때 발생
resize OnResize : 프레임이나 윈도우 크ㄹ기를 변경했을 경우 발생
select Onselect : 입력양식의 한필드를 선택했을때 발생
unload OnUnload : 브라우저의 문서를 닫을때 발생
이벤트 처리의 특징
* 이벤트핸들러의 설정은 window상에서 click 이벤트가 발생하면 자바 스크립트 합수 xxx() 가 실행되게 할때
window.onClick()=xxx(); 라고 입력
예
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>4-2</title>
</head>
<body onLoad = window.open() onBlur ="document.bgColor='blue'" onFocus = "document.bgColor= 'red'">
<h3>포커스를 받으면 빨간색, 잃으면 파란색 배경응로 변합니다. </h3>
</body>
</html>
예) 텍스트 창에 어떤 문자가 입력될때까지 다른 일을 할수 없게 하는 예
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>무제 문서</title>
<script>
function aaa(text){
if(text.value=""){
arlert("이름을 입력하세요");
text.focus();
}
}
</script>
</head>
<body>
<form name="f">
이름<input type="text" name ="t" onBlur="aaa(this)"><br>aaa(this)-->this매개변수는<input type....>에서 의 값을 a()에 넘겨주는 것을 의미
학번<input type= "text" name="id" >
</form>
</body>
</html>
**onChange 핸들러
예) 4글자를 초과하지 못하게 하는 text창 만들기, select 객체의 옵션이 변경되면 변경된 내용을 출력
<html><head>
<script>
function check(text){
if(text.value.length){
alert("입력가능한 최대글자수는 4자입니다.")
text.value=text.value.substring(0,4)
text.focus()
}
}
function checksel(sel){
alert("당신이 선택한 항목은"+sel.options.value)
}
</script></head>
<body>
이름을 입력하는 난에 4글자를 초과하여 입력하면 경고 메세지 출력, 과일 선택이 변경되면 선택된 과일을 경고 메시지 박스와 함께 출력하자
<form name="f">
이름<input type="text" onChange="check(this)"></br>
과일<select name="select" onChange="checksel(this)">
<option value="사과">사과
<option value ="감">감
<option value="배">배
</select>
</form>
</body>
</html>
*onLoad핸들러 : 윈도우 상에서 문서의 로딩 완료 시전ㅁ과 이ㅈ미지의 로딩 완료 시점에 생성
1. 윈도우(프레임)상에서 로딩완료 <body onLoad="">,<frameset onLoad="">
2. 이미지 로딩 완료:<img onLoad ="">
<html>
<body onLoad="alert('어서오세요. 반갑습니다.')"onunLoad="alert('안녕히 가세요.')">
<body>
</html>
*onClick과 onDblClick
예제)계산기 만들기
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>무제 문서</title>
<script>
function compute(f){
var res= eval(f.exp.value); --->eval()함수는 변수를 자바스크립트 의 함수처럼쓰는 명령어 문자열로 입력된 수식을 계산해
주는 내장함수입니다.
f.val.value = res;
}
</script>
</head>
<body>
식난에 계산하고자 하는 수입력후 계산 버튼을 누르시요.<p>
<form name="cal">
식<input type="text" name= "exp" value=""><p>
값<input type="text" name =" val" value="" size="10">
<input type= button value="계산" onClick("computer(this.form)")>(computer(this.form)->객체) 은 computer(document.cal) 과 같다
</form>
</body></html>
[펌] http://blog.naver.com/kdmsal82?Redirect=Log&logNo=150007107406<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
예) window.document.form1.id.value="lee"
코드설명: 현제 브라우저의 창에 존재하는 문서 내용중 "form1" 안에 "id" 객체의 값은 "lee"이다.
주요객체
window : 윈도우마다 하나씩 존재하는 객체로서 윈도우 내에 존재하는 모든객체의 상위 객체이다.
frame:프레임마다 존재하는 객체<frame>태그에 의해 정의 된다.
document : html 페이지마다 존재하는 객체, html문서에 대한 정보를 가진다.
location : 현재 로드된 html페이지의 url에 대한 정보
history : 현재 사용자가 방문하였던 url 들이 리스트를 우지하는 객체이다.
form : 폼에대한 정보를 표헌하는 객체로서 <form>태그당 하나의 객체
계층구조에 따라서 자바 스크립트에 접근
예
<html>
<head>
<title>4-1 계층구조로 객체사용 </title>
</head>
<body>
<form name="f">
<input type ="text" name ="a" value ="나는 자바 스크립트!">
<input type ="text" name ="b" ><p>
<input type ="button" value="복사" onClick ="document.f.b.value = document.f.a.value"><br>
-->******** documet.f.b.value 와 this.form.b.value와 같다. *******
<input type ="button" value="지우기" onClick="this.form.b.value=''" ><p>
</form>
</body>
</html>
****이벤트 ****
이벤트 처리이벤트
abort Onabort : 이미지를 읽는 중에 중지했을때 발생
blur OnBlur :입력양식 필드에서 포커스를 일어 버렸을대 발생(커서가 깜빡일때)
changge OnChange: 입력양식 필드에서 값이 바뀌었을때 발생
click OnClick : 입력양식필드에서 마ㅅ우스를 눌렀을때 발생
dblclick OndblClick : 마우스를 두 번 눌렀을때 발생
dragdrop OnDragDrop: 마우스를 클릭한 상태에서 드래그 했을때 발생
error OnError : 문서나 이미지를 읽는 중에 중지 했을때 발생
focus OnFocus : 입력양식 필드에 포커스가 위치할때 발생
keydown OnKeyDown : 키를 눌렀을때 발생
keypress OnKeyPress : 키를 눌렀다가 놓았을대 발생
keyup OnKeyUp : 키를 놓았을때
load OnLoad :브라우저의 문서를 읽어올때 발생
mousedown OnMouseDown : 마우스 버튼을 눌렀을때 발생
mousemove OnMouseMove : 마우스 위치를 옮겼을때 발생
mouseout OnMouseOut : 마우스가 링크나 영역안에 있다가 벗어났을때 발생
mouseover OnMouseOver : 링크위로 마우스가 위치할때 발생
mouseup OnMouseUp : 마우스를 놓았을때 발생
move OnMove : 프레임이나 우인도를 이동했을 경우에 발생
reset OnReset : 입력양식을 다시 초기화 시켰을때 발생
resize OnResize : 프레임이나 윈도우 크ㄹ기를 변경했을 경우 발생
select Onselect : 입력양식의 한필드를 선택했을때 발생
unload OnUnload : 브라우저의 문서를 닫을때 발생
이벤트 처리의 특징
* 이벤트핸들러의 설정은 window상에서 click 이벤트가 발생하면 자바 스크립트 합수 xxx() 가 실행되게 할때
window.onClick()=xxx(); 라고 입력
예
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>4-2</title>
</head>
<body onLoad = window.open() onBlur ="document.bgColor='blue'" onFocus = "document.bgColor= 'red'">
<h3>포커스를 받으면 빨간색, 잃으면 파란색 배경응로 변합니다. </h3>
</body>
</html>
예) 텍스트 창에 어떤 문자가 입력될때까지 다른 일을 할수 없게 하는 예
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>무제 문서</title>
<script>
function aaa(text){
if(text.value=""){
arlert("이름을 입력하세요");
text.focus();
}
}
</script>
</head>
<body>
<form name="f">
이름<input type="text" name ="t" onBlur="aaa(this)"><br>aaa(this)-->this매개변수는<input type....>에서 의 값을 a()에 넘겨주는 것을 의미
학번<input type= "text" name="id" >
</form>
</body>
</html>
**onChange 핸들러
예) 4글자를 초과하지 못하게 하는 text창 만들기, select 객체의 옵션이 변경되면 변경된 내용을 출력
<html><head>
<script>
function check(text){
if(text.value.length){
alert("입력가능한 최대글자수는 4자입니다.")
text.value=text.value.substring(0,4)
text.focus()
}
}
function checksel(sel){
alert("당신이 선택한 항목은"+sel.options.value)
}
</script></head>
<body>
이름을 입력하는 난에 4글자를 초과하여 입력하면 경고 메세지 출력, 과일 선택이 변경되면 선택된 과일을 경고 메시지 박스와 함께 출력하자
<form name="f">
이름<input type="text" onChange="check(this)"></br>
과일<select name="select" onChange="checksel(this)">
<option value="사과">사과
<option value ="감">감
<option value="배">배
</select>
</form>
</body>
</html>
*onLoad핸들러 : 윈도우 상에서 문서의 로딩 완료 시전ㅁ과 이ㅈ미지의 로딩 완료 시점에 생성
1. 윈도우(프레임)상에서 로딩완료 <body onLoad="">,<frameset onLoad="">
2. 이미지 로딩 완료:<img onLoad ="">
<html>
<body onLoad="alert('어서오세요. 반갑습니다.')"onunLoad="alert('안녕히 가세요.')">
<body>
</html>
*onClick과 onDblClick
예제)계산기 만들기
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>무제 문서</title>
<script>
function compute(f){
var res= eval(f.exp.value); --->eval()함수는 변수를 자바스크립트 의 함수처럼쓰는 명령어 문자열로 입력된 수식을 계산해
주는 내장함수입니다.
f.val.value = res;
}
</script>
</head>
<body>
식난에 계산하고자 하는 수입력후 계산 버튼을 누르시요.<p>
<form name="cal">
식<input type="text" name= "exp" value=""><p>
값<input type="text" name =" val" value="" size="10">
<input type= button value="계산" onClick("computer(this.form)")>(computer(this.form)->객체) 은 computer(document.cal) 과 같다
</form>
</body></html>
[펌] http://blog.naver.com/kdmsal82?Redirect=Log&logNo=150007107406<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
댓글 2개
19년 전
좋은 정보 감사합니다...
19년 전
document.form.id... 라는 것은 이젠 옛말이 아닐까 합니다.
앞으로 나올 그누5나, 다음이라도 해당 코드는
document.forms['form'].elements['id'] 가 되야 될 것 입니다.
앞으로 나올 그누5나, 다음이라도 해당 코드는
document.forms['form'].elements['id'] 가 되야 될 것 입니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 830 |
|
19년 전 | 2184 | |
| 829 |
|
19년 전 | 1917 | |
| 828 |
|
19년 전 | 1807 | |
| 827 |
|
19년 전 | 1654 | |
| 826 |
|
19년 전 | 1848 | |
| 825 |
|
19년 전 | 1888 | |
| 824 |
|
19년 전 | 1943 | |
| 823 |
|
19년 전 | 2687 | |
| 822 |
|
19년 전 | 5316 | |
| 821 |
|
19년 전 | 1722 | |
| 820 |
|
19년 전 | 1573 | |
| 819 |
|
19년 전 | 1436 | |
| 818 |
|
19년 전 | 1598 | |
| 817 |
|
19년 전 | 1521 | |
| 816 |
|
19년 전 | 1444 | |
| 815 |
|
19년 전 | 1457 | |
| 814 |
|
19년 전 | 1378 | |
| 813 |
|
19년 전 | 1442 | |
| 812 | 19년 전 | 2816 | ||
| 811 |
pearly
|
19년 전 | 3834 | |
| 810 |
pearly
|
19년 전 | 5210 | |
| 809 |
|
19년 전 | 1375 | |
| 808 |
pearly
|
19년 전 | 4539 | |
| 807 | 19년 전 | 2979 | ||
| 806 |
|
19년 전 | 1498 | |
| 805 |
|
19년 전 | 2691 | |
| 804 |
|
19년 전 | 3616 | |
| 803 |
|
19년 전 | 1800 | |
| 802 |
|
19년 전 | 3789 | |
| 801 |
|
19년 전 | 1881 | |
| 800 | 19년 전 | 3771 | ||
| 799 | 19년 전 | 3431 | ||
| 798 | 19년 전 | 4204 | ||
| 797 | 19년 전 | 4059 | ||
| 796 |
|
19년 전 | 1895 | |
| 795 |
|
19년 전 | 1849 | |
| 794 | 19년 전 | 4274 | ||
| 793 | 19년 전 | 2668 | ||
| 792 | 19년 전 | 2544 | ||
| 791 | 19년 전 | 2394 | ||
| 790 | 19년 전 | 1971 | ||
| 789 | 19년 전 | 2591 | ||
| 788 | 19년 전 | 2205 | ||
| 787 | 19년 전 | 1845 | ||
| 786 | 19년 전 | 1971 | ||
| 785 | 19년 전 | 1441 | ||
| 784 |
|
19년 전 | 1694 | |
| 783 | 19년 전 | 2836 | ||
| 782 |
|
19년 전 | 1956 | |
| 781 | 19년 전 | 3247 | ||
| 780 | 19년 전 | 3156 | ||
| 779 |
|
19년 전 | 2243 | |
| 778 |
|
19년 전 | 1796 | |
| 777 | 19년 전 | 2836 | ||
| 776 | 19년 전 | 2899 | ||
| 775 | 19년 전 | 4017 | ||
| 774 |
|
19년 전 | 1975 | |
| 773 | 19년 전 | 2620 | ||
| 772 | 19년 전 | 2337 | ||
| 771 | 19년 전 | 3469 | ||
| 770 |
|
19년 전 | 1434 | |
| 769 | 19년 전 | 1496 | ||
| 768 | 19년 전 | 1767 | ||
| 767 | 19년 전 | 2202 | ||
| 766 | 19년 전 | 1833 | ||
| 765 | 19년 전 | 1693 | ||
| 764 |
|
19년 전 | 2107 | |
| 763 |
|
19년 전 | 2216 | |
| 762 |
|
19년 전 | 4963 | |
| 761 | 19년 전 | 2326 | ||
| 760 |
|
19년 전 | 3192 | |
| 759 | 19년 전 | 2641 | ||
| 758 |
|
19년 전 | 2405 | |
| 757 | 19년 전 | 4697 | ||
| 756 | 19년 전 | 2561 | ||
| 755 |
|
19년 전 | 2413 | |
| 754 |
|
19년 전 | 1951 | |
| 753 |
|
19년 전 | 1733 | |
| 752 |
pearly
|
19년 전 | 3367 | |
| 751 | 19년 전 | 2344 | ||
| 750 |
|
19년 전 | 6159 | |
| 749 | 19년 전 | 2027 | ||
| 748 |
|
19년 전 | 1902 | |
| 747 |
|
19년 전 | 2704 | |
| 746 |
|
19년 전 | 1813 | |
| 745 | 19년 전 | 2281 | ||
| 744 | 19년 전 | 2111 | ||
| 743 |
|
19년 전 | 3564 | |
| 742 | 19년 전 | 2578 | ||
| 741 | 19년 전 | 2746 | ||
| 740 |
|
19년 전 | 4366 | |
| 739 | 19년 전 | 3547 | ||
| 738 |
|
19년 전 | 2306 | |
| 737 | 19년 전 | 4308 | ||
| 736 | 19년 전 | 3266 | ||
| 735 |
홀로남은자
|
19년 전 | 4137 | |
| 734 |
홀로남은자
|
19년 전 | 2023 | |
| 733 |
홀로남은자
|
19년 전 | 2227 | |
| 732 | 19년 전 | 2139 | ||
| 731 | 19년 전 | 3354 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기