๐2022-08-05๐
ex9-01.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML ํ๊ทธ์ ๋ฆฌ์ค๋ ์์ฑ</title>
</head>
<body>
<h3>HTML ํ๊ทธ์ ๋ฆฌ์ค๋ ์์ฑ</h3>
<hr>
<p onmouseover="this.style.backgroundColor='orchid'"
onmouseout="this.style.backgroundColor='white'">
๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด orchid ์์ผ๋ก ๋ณ๊ฒฝ</p>
</body>
</html>
ex9-02.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM ๊ฐ์ฒด์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ํ๋กํผํฐ์ ํจ์ ๋ฑ๋ก</title>
<script>
let p;
function init() { // ๋ฌธ์๊ฐ ์์ ํ ๋ก๋๋์์ ๋ ํธ์ถ
p = document.getElementById("p");
p.onmouseover = over; // over() ํจ์๋ฅผ onmouseover ๋ฆฌ์ค๋๋ก ๋ฑ๋ก
p.onmouseout = out; // out() ํจ์๋ฅผ onmouseout ๋ฆฌ์ค๋๋ก ๋ฑ๋ก
}
function over() {
p.style.backgroundColor="orchid";
}
function out() {
p.style.backgroundColor="white";
}
</script></head>
<body onload="init()">
<h3>DOM ๊ฐ์ฒด์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ํ๋กํผํฐ์ ํจ์ ๋ฑ๋ก</h3>
<hr>
<p id="p">๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด orchid ์์ผ๋ก ๋ณ๊ฒฝ</p>
</body>
</html>
ex9-03.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>addEventListener()๋ฅผ ์ด์ฉํ ๋ฆฌ์ค๋ ๋ฑ๋ก</title>
<script>
let p;
function init() { // ๋ฌธ์๊ฐ ์์ ํ ๋ก๋๋์์ ๋ ํธ์ถ
p = document.getElementById("p");
p.addEventListener("mouseover", over); // ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
p.addEventListener("mouseout", out); // ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
}
function over() {
p.style.backgroundColor="orchid";
}
function out() {
p.style.backgroundColor="white";
}
</script>
</head>
<body onload="init()">
<h3>addEventListener()๋ฅผ ์ด์ฉํ ๋ฆฌ์ค๋ ๋ฑ๋ก</h3>
<hr>
<p id="p">๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด orchid ์์ผ๋ก ๋ณ๊ฒฝ</p>
</body>
</html>
ex9-04.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ต๋ช
ํจ์๋ก ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์์ฑ</title>
<script>
let p;
function init() { // ๋ฌธ์๊ฐ ์์ ํ ๋ก๋๋์์ ๋ ํธ์ถ
p = document.getElementById("p");
p.onmouseover = function () { // ์ต๋ช
ํจ์
this.style.backgroundColor = "orchid";
};
p.addEventListener("mouseout",
function () { this.style.backgroundColor="white"; } // ์ต๋ช
ํจ์
);
}
</script>
</head>
<body onload="init()">
<h3>์ต๋ช
ํจ์๋ก ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์์ฑ</h3>
<hr>
<p id="p">๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด orchid ์์ผ๋ก ๋ณ๊ฒฝ</p>
</body>
</html>
ex9-05.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ด๋ฒคํธ ๊ฐ์ฒด ์ ๋ฌ๋ฐ๊ธฐ</title>
</head>
<body>
<p id="p">๋ง์ฐ์ค๋ฅผ ์ฌ๋ ค ๋ณด์ธ์</p>
<button onclick="f(event)">ํด๋ฆญํ์ธ์</button>
<script>
function f(e) { // e๋ ํ์ฌ ๋ฐ์ํ ์ด๋ฒคํธ ๊ฐ์ฒด
alert(e.type); // ์ด๋ฒคํธ ์ข
๋ฅ ์ถ๋ ฅ
}
document.getElementById("p").onmouseover = f; // ์๋์ผ๋ก ์ด๋ฒคํธ ๊ฐ์ฒด ๋๊ฒจ์ค
</script>
</body>
</html>
ex9-06.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ด๋ฒคํธ ๊ฐ์ฒด ํ๋กํผํฐ</title>
</head>
<body>
<h3>์ด๋ฒคํธ ๊ฐ์ฒด์ ํ๋กํผํฐ ์ถ๋ ฅ</h3>
<hr>
<p id="p">๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ด๋ฒคํธ ๊ฐ์ฒด๋ฅผ ์ถ๋ ฅํฉ๋๋ค.</p>
<button onclick="f(event)">ํด๋ฆญํ์ธ์</button>
<script>
function f(e) { // e๋ ํ์ฌ ๋ฐ์ํ ์ด๋ฒคํธ ๊ฐ์ฒด
let text = "type: " + e.type + "<br>"
+ "target: " + e.target + "<br>"
+ "currentTarget: " + e.currentTarget + "<br>"
+ "defaultPrevented: " + e.defaultPrevented;
let p = document.getElementById("p");
p.innerHTML = text; // ์ด๋ฒคํธ ๊ฐ์ฒด์ ํ๋กํผํฐ ์ถ๋ ฅ
}
</script>
</body>
</html>
ex9-07.html
์ด๋ฒคํธ์ ๋ํดํธ ํ๋ ์ทจ์
๋ค์ด๋ฒ๋ก ์ด๋ํ ์ง ๋ฌผ์ด๋ณด๋ ๋งํฌ
ex9-08.html
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title>์ด๋ฒคํธ ํ๋ฆ</title></head>
<body>
<p style="color:blue">์ด๊ฒ์
<span style="color:red" id="span">๋ฌธ์ฅ์
๋๋ค.
</span>
</p>
<form>
<input type="text" name="s">
<input type="button" value="ํ
์คํธ" id="button">
<hr>
</form>
<div id="div" style="color:green"></div>
<script>
let div = document.getElementById("div"); // ์ด๋ฒคํธ ๋ฉ์์ง ์ถ๋ ฅ ๊ณต๊ฐ
let button = document.getElementById("button");
// body ๊ฐ์ฒด์ ์บก์ณ ๋ฆฌ์ค๋ ๋ฑ๋ก
document.body.addEventListener("click", capture, true); // ์ผญ์ณ ๋จ๊ณ(1)
// ํ๊ฒ ๊ฐ์ฒด์ ๋ฒ๋ธ ๋ฆฌ์ค๋ ๋ฑ๋ก
button.addEventListener("click", bubble, false); // ๋ฒ๋ธ ๋จ๊ณ(2)
// body ๊ฐ์ฒด์ ๋ฒ๋ธ ๋ฆฌ์ค๋ ๋ฑ๋ก
document.body.addEventListener("click", bubble, false); // ๋ฒ๋ธ ๋จ๊ณ(3)
function capture(e) { // e๋ ์ด๋ฒคํธ ๊ฐ์ฒด
let obj = e.currentTarget; // ํ์ฌ ์ด๋ฒคํธ๋ฅผ ๋ฐ์ DOM ๊ฐ์ฒด
let tagName = obj.tagName; // ํ๊ทธ ์ด๋ฆ
div.innerHTML += "<br>capture ๋จ๊ณ : " + tagName + " ํ๊ทธ " + e.type + "์ด๋ฒคํธ";
}
function bubble(e) { // e๋ ์ด๋ฒคํธ ๊ฐ์ฒด
let obj = e.currentTarget; // ํ์ฌ ์ด๋ฒคํธ๋ฅผ ๋ฐ์ DOM ๊ฐ์ฒด
let tagName = obj.tagName; // ํ๊ทธ ์ด๋ฆ
div.innerHTML += "<br>bubble ๋จ๊ณ : " + tagName + " ํ๊ทธ " + e.type + "์ด๋ฒคํธ";
}
</script>
</body>
</html>
ex9-09.html
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title>onclick</title>
<script>
function calculate() {
let exp = document.querySelector("#exp");
let result = document.querySelector("#result");
result.value = eval(exp.value);
}
</script>
</head>
<body >
<h3> onclick, ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ</h3>
<hr>
๊ณ์ฐํ๊ณ ์ ํ๋ ์์์
์
๋ ฅํ๊ณ ๊ณ์ฐ ๋ฒํผ์ ๋๋ฌ๋ด์.
<br>
<br>
<form>
์ <input type="text" id="exp" value=""><br>
๊ฐ <input type="text" id ="result">
<input type="button" value=" ๊ณ์ฐ "
onclick="calculate()">
</form>
</body>
</html>
ex9-10.html
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title>๋ง์ฐ์ค ๊ด๋ จ ๋ฆฌ์ค๋</title>
<script>
let width=1; // ํ
๋๋ฆฌ ๋๊ป
function down(obj) {
obj.style.fontStyle = "italic";
}
function up(obj) {
obj.style.fontStyle = "normal";
}
function over(obj) {
obj.style.borderColor = "violet";
// ํ
๋๋ฆฌ ํญ์ด 0์ผ ๋ ์์ ๋ณด์ด์ง ์๋๋ค.
}
function out(obj) {
obj.style.borderColor = "lightgray";
}
function wheel(e, obj) { // e๋ ์ด๋ฒคํธ ๊ฐ์ฒด
if(e.wheelDelta < 0) { // ํ ์ ์๋๋ก ๊ตด๋ฆด ๋
width--; // ํญ 1 ๊ฐ์
if(width < 0) width = 0; // ํญ์ด 0๋ณด๋ค ์์์ง์ง ์๊ฒ
}
else // ํ ์ ์๋ก ๊ตด๋ฆด ๋
width++; // ํญ 1 ์ฆ๊ฐ
obj.style.borderStyle = "ridge";
obj.style.borderWidth = width+"px";
}
</script>
</head>
<body >
<h3>๋ง์ฐ์ค ๊ด๋ จ ์ด๋ฒคํธ ๋ฆฌ์ค๋</h3>
<hr>
<div>๋ง์ฐ์ค ๊ด๋ จ
<span onmousedown="down(this)"
onmouseup="up(this)"
onmouseover="over(this)"
onmouseout="out(this)"
onwheel="wheel(event, this)"
style="display:inline-block">์ด๋ฒคํธ
</span>๊ฐ ๋ฐ์ํฉ๋๋ค.
</div>
</body>
</html>
ex9-11.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๋ง์ฐ์ค ์ด๋ฒคํธ ๊ฐ์ฒด์ ํ๋กํผํฐ</title>
<style>
div {
background : skyblue;
width : 250px;
}
</style>
</head>
<body>
<h3>๋ง์ฐ์ค ์ด๋ฒคํธ ๊ฐ์ฒด์ ํ๋กํผํฐ์ onmousemove</h3>
<hr>
์ด๋ฏธ์ง ์์ ๋ง์ฐ์ค๋ฅผ ์์ง์ผ ๋ onmousemove ๋ฆฌ์ค๋๊ฐ ์คํ๋๊ณ ,
๋ง์ฐ์ค์ ์์น๋ฅผ ๋ณด์ฌ์ค๋๋ค.<br><br>
<img src="media/beach.png" onmousemove="where(event)"><br><br>
<div id="div"></div>
<script>
let div = document.getElementById("div");
function where(e) {
let text = "๋ฒํผ=" + e.button + "<br>";
text += "(screenX, screenY)=" + e.screenX + "," + e.screenY + "<br>";
text += "(clientX, clientY)=" + e.clientX + "," + e.clientY + "<br>";
text += "(offsetX, offsetY)=" + e.offsetX + "," + e.offsetY + "<br>";
text += "(x, y)=" + e.x + "," + e.y + "\n";
div.innerHTML = text;
}
</script>
</body>
</html>
ex9-12.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>oncontextmenu</title>
<script>
function hideMenu() {
alert("์ค๋ฅธ์ชฝ ํด๋ฆญ<์ปจํ
์คํธ ๋ฉ๋ด>๊ธ์ง");
return false;
}
document.oncontextmenu=hideMenu;
</script>
</head>
<body>
<h3>oncontextmenu์์ ์ปจํ
์คํธ ๋ฉ๋ด ๊ธ์ง</h3>
<hr>
๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ํด๋ฆญ์ ๊ธ์ง๋ฉ๋๋ค. ์๋ฌด๊ณณ์ด๋
ํด๋ฆญํด๋ ์ปจํ
์คํธ ๋ฉ๋ด๋ฅผ ๋ณผ ์ ์์ต๋๋ค.<br>
<img src="media/beach2.png" alt="miami">
</body>
</html>
ex9-13.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML ๋ฌธ์์ onload</title>
</head>
<body onload="alert('์ด ์ฌ์ดํธ๋ 2022๋
9์1์ผ๋ถํฐ \
www.js.co.kr๋ก ์ฎ๊ฒจ์ง๊ฒ ๋ฉ๋๋ค.')">
<h3>HTML ๋ฌธ์์ ๋ก๋ฉ ์๋ฃ, onload</h3>
<hr>
์ด ํ์ด์ง๋ onload ๋ฆฌ์ค๋์ ์ฌ์ฉ ์๋ฅผ ๋ณด์ฌ์ค๋๋ค
์ด ํ์ด์ง๊ฐ ์ถ๋ ฅ๋๊ณ ๋ ๋ฐ๋ก ์งํ onload ๋ฆฌ์ค๋๋ฅผ ํตํด
๊ฒฝ๊ณ ์ฐฝ์ ์ถ๋ ฅํฉ๋๋ค.
</body>
</html>
ex9-14.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onload๋ก ์ด๋ฏธ์ง ํฌ๊ธฐ ์ถ๋ ฅ</title>
<script>
function changeImage() {
let sel = document.getElementById("sel");
let img = document.getElementById("myImg");
img.onload = function () {
// ์ด๋ฏธ์ง ํฌ๊ธฐ ์ถ๋ ฅ
let mySpan = document.getElementById("mySpan");
mySpan.innerHTML = img.width + "x" + img.height;
}
let index= sel.selectedIndex; // ์ ํ๋ ์ต์
์ธ๋ฑ์ค
img.src = sel.options[index].value; // <option>์ value ์์ฑ
// ์ด๋ฏธ์ง ๋ก๋ฉ ์์, ์๋ฃ ํ onload ๋ฆฌ์ค๋ ํธ์ถ
}
</script>
</head>
<body onload="changeImage()">
<h3>onload๋ก ์ด๋ฏธ์ง ํฌ๊ธฐ ์ถ๋ ฅ</h3>
<hr>
<form>
<select id="sel" onchange="changeImage()">
<option value="media/apple.png">์ฌ๊ณผ
<option value="media/banana.png">๋ฐ๋๋
<option value="media/mango.png">๋ง๊ณ
</select>
<span id="mySpan">์ด๋ฏธ์ง ํฌ๊ธฐ</span>
</form>
<p><img id="myImg" src="media/apple.png" alt="."></p>
</body>
</html>
ex9-15.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>new Image()๋ก ์ด๋ฏธ์ง ๋ก๋ฉ</title>
<script>
// ๋ฏธ๋ฆฌ ๋ก๋ฉํด ๋ 8๊ฐ์ ์ด๋ฏธ์ง ํ์ผ ์ด๋ฆ ๋ฐฐ์ด
let files = ["media/Penguins.png",
"media/Lighthouse.png",
"media/Chrysanthemum.png",
"media/Desert.png",
"media/Hydrangeas.png",
"media/Jellyfish.png",
"media/Koala.png",
"media/Tulips.png"];
let imgs = new Array(); // ์ด๋ฏธ์ง ๊ฐ์ฒด๋ฅผ ์ ์ฅํ ๋ฐฐ์ด
for(let i=0; i<files.length; i++) {
imgs[i] = new Image(); // ์ด๋ฏธ์ง ๊ฐ์ฒด ์์ฑ
imgs[i].src = files[i]; // ์ด๋ฏธ์ง ๋ก๋ฉ ์ง์
}
let next = 1;
function change(img) { // ๋ค์ ์ด๋ฏธ์ง ์ถ๋ ฅ
img.src = imgs[next].src; // ์ด๋ฏธ์ง ๋ณ๊ฒฝ
next++; // ๋ค์ ์ด๋ฏธ์ง์ ๋ํ ์ธ๋ฑ์ค
next %= imgs.length; // ๊ฐ์๋ฅผ ๋์ผ๋ฉด ์ฒ์์ผ๋ก
}
</script>
</head>
<body>
<h3>new Image()๋ก ์ด๋ฏธ์ง ๋ก๋ฉ</h3>
<hr>
์ด๋ฏธ์ง๋ฅผ ํด๋ฆญํ๋ฉด ๋ค์ ์ด๋ฏธ์ง๋ฅผ ๋ณด์ฌ์ค๋๋ค.<p>
<img style="border:20px ridge wheat"
src="media/Penguins.png" alt="."
width="200" height="200"
onclick="change(this)">
</body>
</html>
ex9-16.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onfocus์ onblur</title>
<script>
function checkFilled(obj) {
if(obj.value == "") { // obj์ ์
๋ ฅ๋ ๊ฒ์ด ์๋ค๋ฉด
obj.focus(); // obj์ ๋ค์ ํฌ์ปค์ค
}
}
</script>
</head>
<body onload=
"document.getElementById('name').focus();">
<h3>onfocus์ onblur</h3>
<hr>
<p>์ด๋ฆ์ ์
๋ ฅํ์ง ์๊ณ ๋ค๋ฅธ ์ฐฝ์ผ๋ก
์ด๋ํ ์ ์์ต๋๋ค.</p>
<form>
์ด๋ฆ <input type="text" id="name"
onblur="checkFilled(this)"><p>
ํ๋ฒ <input type="text">
</form>
</body>
</html>
ex9-17.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ ํ๋ ๋ผ๋์ค๋ฒํผ ์์๋ด๊ธฐ</title>
<script>
function findChecked() {
let found = null;
let kcity = document.getElementsByName("city");
for(let i=0; i<kcity.length; i++) {
if(kcity[i].checked == true)
found = kcity[i];
}
if(found != null)
alert(found.value + "์ด ์ ํ๋์์");
else
alert("์ ํ๋ ๊ฒ์ด ์์");
}
</script>
</head>
<body>
<h3>๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ ํ๋ ๋ผ๋์ค ๋ฒํผ์ value๋ฅผ ์ถ๋ ฅํฉ๋๋ค.</h3>
<hr>
<form>
<input type="radio" name="city" value="seoul" checked>์์ธ
<input type="radio" name="city" value="busan">๋ถ์ฐ
<input type="radio" name="city" value="chunchen">์ถ์ฒ
<input type="button" value="find checked" onclick="findChecked()">
</form>
</body>
</html>
ex9-18.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ ํ๋ ๋ฌผํ ๊ณ์ฐํ๊ธฐ</title>
<script>
let sum=0;
function calc(cBox) {
if(cBox.checked)
sum += parseInt(cBox.value);
else
sum -= parseInt(cBox.value);
document.getElementById("sumtext").value = sum;
}
</script>
</head>
<body>
<h3>๋ฌผํ์ ์ ํํ๋ฉด ๊ธ์ก์ด ์๋ ๊ณ์ฐ๋ฉ๋๋ค</h3>
<hr>
<form>
<input type="checkbox" name="hap" value="10000"
onclick="calc(this)">๋ชจ์ 1๋ง์
<input type="checkbox" name="shose" value="30000"
onclick="calc(this)">๊ตฌ๋ 3๋ง์
<input type="checkbox" name="bag" value="80000"
onclick="calc(this)">๋ช
ํ๊ฐ๋ฐฉ 8๋ง์<br>
์ง๋ถํ์ค ๊ธ์ก <input type="text" id="sumtext" value="0" >
</form>
</body>
</html>
ex9-19.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>select ๊ฐ์ฒด์์ ์ ํํ ๊ณผ์ผ์ถ๋ ฅ</title>
<script>
function drawImage() {
let sel = document.getElementById("fruits");
let img = document.getElementById("fruitimage");
img.src = sel.options[sel.selectedIndex].value;
}
</script>
</head>
<body onload="drawImage()">
<h3>select ๊ฐ์ฒด์์ ์ ํํ ๊ณผ์ผ ์ถ๋ ฅ</h3>
<hr>
๊ณผ์ผ์ ์ ํํ๋ฉด ์ด๋ฏธ์ง๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค.<p>
<form>
<select id="fruits" onchange="drawImage()">
<option value="media/strawberry.png">๋ธ๊ธฐ
<option value="media/banana.png" selected>๋ฐ๋๋
<option value="media/apple.png">์ฌ๊ณผ
</select>
<img id="fruitimage" src="media/banana.gif" alt="">
</form>
</body>
</html>
ex9-20.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํค ์ด๋ฒคํธ</title>
<script>
function whatKeyDown(e) {
let str = "";
let div = document.getElementById("div");
div.innerHTML = ""; // div ๊ฐ์ฒด ๋ด์ฉ ์ด๊ธฐํ
str += "e.key = " + e.key + "<br>";
str += "e.code = " + e.code + "<br>";
div.innerHTML = str; // div ๊ฐ์ฒด์ html ๋ฌธ์์ด ์ถ๋ ฅ
}
</script>
</head>
<body>
<h3>ํค ๋ฆฌ์ค๋์ ํค ์ด๋ฒคํธ ๊ฐ์ฒด์ ํ๋กํผํฐ</h3>
<hr>
ํ
์คํธ ์ฐฝ์ ํค๋ฅผ ๋๋ฌ ๋ณด์ธ์. Alt, Shift, Ctrl ํค๋ ๊ฐ๋ฅํฉ๋๋ค.<br>
<input type="text" id="text" onkeydown="whatKeyDown(event)">
<div id="div" style="background-color:skyblue; width:250px; height:50px">
</div>
</body>
</html>
ex9-21.html
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>ํค ์ด๋ฒคํธ ์์ฉ</title>
<style>
td { width:50px; height:50px; border:1px solid orchid; }
</style>
<script>
let tds;
let prevIndex=0, index=0;
window.onload = function () { // ์น ํ์ด์ง์ ๋ก๋ฉ ์๋ฃ์ ์คํ
tds = document.getElementsByTagName("td");
tds[index].style.backgroundColor = "orchid";
}
window.onkeydown = function (e) {
switch(e.key) {
case "ArrowDown" :
if(index/3 >= 2) return; // ๋งจ ์ ์
์ ๊ฒฝ์ฐ
index += 3;
break;
case "ArrowUp" :
if(index/3 < 1) return; // ๋งจ ์๋ ์
์ ๊ฒฝ์ฐ
index -= 3;
break;
case "ArrowLeft" :
if(index%3 == 0) return; // ๋งจ ์ผ์ชฝ ์
์ ๊ฒฝ์ฐ
index--;
break;
case "ArrowRight" :
if(index%3 == 2) return; // ๋งจ ์ค๋ฅธ์ชฝ ์
์ ๊ฒฝ์ฐ
index++;
break;
}
tds[index].style.backgroundColor = "orchid";
tds[prevIndex].style.backgroundColor = "white";
prevIndex = index;
}
</script></head>
<body>
<h3>์ํ์ข์ฐ ํค๋ก ์
์ด๋ํ๊ธฐ</h3><hr>
<table>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
</table>
</body></html>
'IT > HTML' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[35์ผ์ฐจ] ์น ํ์ด์ง ์ ์ (0) | 2022.08.08 |
---|---|
[34์ผ์ฐจ] 10์ฅ ์๋์ฐ์ ๋ธ๋ผ์ฐ์ ๊ด๋ จ ๊ฐ์ฒด (0) | 2022.08.05 |
[34์ผ์ฐจ] 8์ฅ HTML DOM๊ณผ Document (0) | 2022.08.05 |
[33์ผ์ฐจ] 7์ฅ ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ์ด ๊ฐ์ฒด์ ๋ฐฐ์ด (0) | 2022.08.04 |
[33์ผ์ฐจ] js02 (0) | 2022.08.04 |
๋๊ธ