ex11
CSS : ์ ํ์ > ํ๊ทธ ๊ฒ์ > ์ ๊ทผ > ์์ ์กฐ์
JavaScript : ๊ฒ์๋๊ตฌ > ํ๊ทธ ๊ฒ์ > ์ ๊ทผ > ํ๊ทธ ์กฐ์
HTML ๊ณ์ธต ๊ตฌ์กฐ ํ์ฉ + JavaScript ํ์
1. BOM, Browser Object Model
- ์ด์ฐฝ๊ธฐ ๋ชจ๋ธ
- ํ์ฌ๊น์ง ์ฌ์ฉ
- ์ ํ์ ๋ชจ๋ธ > ์ผ๋ถ ํ๊ทธ๋ง ๊ด๋ฆฌ > ์ผ๋ถ ํ๊ทธ๋ง ์กฐ์ ๊ฐ๋ฅ > ๋น ์ง ํ๊ทธ๋ ์กฐ์ ๋ถ๊ฐ๋ฅ
- ์ด๋ฏธ์ง, ๋งํฌ, ํผ ํ๊ทธ ์ด์ธ์๋ ์กฐ์์ด ๋ถํ์ํ๋ค๊ณ ํ๋จ.
- ํ๊ทธ์ name์ ์ฌ์ฉํด์ ์ ๊ทผ
- id, class๋ ์ธ์ ๋ถ๊ฐ๋ฅ
2. DOM, Document Object Model
- BOM > ๊ฐ์ ํ ๋ชจ๋ธ
- ํ์ฌ๊น์ง ๊ณ์ ์ฌ์ฉ(์ฃผ๋ ฅ)
- BOM ๊ธฐ๋ฐ + ๊ธฐ๋ฅ ์ถ๊ฐ
- ๋ชจ๋ ํ๊ทธ๋ฅผ ์ธ์ > ๋ชจ๋ ํ๊ทธ๋ฅผ ์กฐ์
- name, id, class ๋ชจ๋ ์ธ์ ๊ฐ๋ฅ
<body>
<img src="images/catty01.png" name="cat1">
<hr>
<form name="form1">
<div>
<input type="text" name="txt1">
</div>
</form>
<form name="form2">
<div>
<input type="text" name="txt2">
</div>
</form>
<script>
//ํ๊ทธ์ ์ ๊ทผ
window.document.images[0].title = '๊ณ ์์ด';
window.document.form1.txt1.size = 10;
window.document.form2.txt2.value = 'ํ๊ธธ๋';
// window.close(); //์ฐฝ ๋ซํ
//window.document
</script>
</body>
</html>
ex12
Event
JavaScript Event
- ์ฌ๊ฑด
- ๊ฐ์ฒด(ํน์ ํ๊ทธ)์์ ๋ฐ์ํ๋ ์ฌ๊ฑด
- ์ธ์ ๋ฐ์ํ ์ง ์์ธก ๋ถ๊ฐ๋ฅ(์๊ฐ)
JavaScript Event Handling
- ์ด๋ฒคํธ ๋ฑ๋ก(๊ตฌํ)
- ์ฌ๊ฑด ์ฒ๋ฆฌ
- ์ธ์ ๋ฐ์ํ ์ง ์์ธก ๋ถ๊ฐ๋ฅํ ์ฌ๊ฑด์ ๋ํด ์ฒ๋ฆฌ๋ฅผ ํ๊ณ ์ถ๋ค. > ์ธ์ ๊ฐ ์ฌ๊ฑด์ด ๋ฐ์ํ๋ฉด ์ฒ๋ฆฌํ๊ธฐ ์ํ ์ฝ๋๋ฅผ ๋ฏธ๋ฆฌ ์ค๋นํ๋ค. > ์ฌ๊ฑด๊ณผ ์ฐ๊ฒฐ > ์ด๋ฒคํธ ์ฒ๋ฆฌ, ์ด๋ฒคํธ ๋งคํ, ์ด๋ฒคํธ ๊ตฌํ ๋ฑ..
์ด๋ฒคํธ ๋ฑ๋ก
1. ์ ์
- HTML ํ๊ทธ์ ์ง์ ์ ์ฉ
<body>
<!-- ex12_event.html -->
<h1>Event</h1>
<form name="form1">
<input type="text" name="txt1">
<input type="button" value="ํ์ธ(์ ์ )" name="btn1" onclick="window.document.form1.txt1.value = 'ํ๊ธธ๋';">
<input type="button" value="ํ์ธ(๋์ )" name="btn2">
</form>
<script>
</script>
</body>
</html>
2. ๋์
- JavaScript ์ฝ๋๋ฅผ ์ฌ์ฉ
<script>
window.document.form1.btn2.onclick = m1; //ํจ์ ํฌ์ธํฐ
function m1() {
//์ฝ๋ ์์ฑ
window.document.form1.txt1.value = '์๋ฌด๊ฐ';
}
</script>
<script>
var now = new Date();
if (now.getHours() < 12) {
//์ค์
window.document.form1.btn2.onclick = m2;
} else {
//์คํ
window.document.form1.btn2.onclick = m3;
}
function m2() {
window.document.form1.txt1.value = '์ค์ ์
๋๋ค.';
}
function m3() {
window.document.form1.txt1.value = '์คํ์
๋๋ค.';
}
</script>
ํ๋ฉด
Event
'ํ๋ก๊ทธ๋๋ฐ ๊ณต๋ถ > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ex15~16] Attribute, images (0) | 2023.04.21 |
---|---|
[ex13~14] Mouse Event, Key Event (0) | 2023.04.21 |
[ex09~10] Date, Array (0) | 2023.04.21 |
[ex06~08] scope, casting, string (0) | 2023.04.21 |
[ex02~05] JavaScript (0) | 2023.04.20 |