15-4. JS DOM ์—ฐ์Šต๋ฌธ์ œ 1,2

2021. 10. 22. 23:27ใ†HTML + CSS + JS

728x90

* ์—ฐ์Šต๋ฌธ์ œ 1

์ฒดํฌํ•˜๋ฉด ๊ฐ€๋กœ์ค„์ด ๊ทธ์–ด์ง€๋„๋ก 

<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>์—ฐ์Šต๋ฌธ์ œ 1</title>
	<style>
		ul{
			list-style: none;
		}
		li {
			font-size:20px; 
			line-height: 35px;
		}
		.check {			
			color:#ccc;
			font-size:20px;
			margin-right:25px;
		}
		.check:hover {
			color:#222;
		}
	</style>
</head>
<body>
	<h1>ํ•  ์ผ ๋ชฉ๋ก</h1>
	<ul>
		<li><span class="check">&check;</span>ํ•  ์ผ 1 </li>
		<li><span class="check">&check;</span>ํ•  ์ผ 2 </li>
		<li><span class="check">&check;</span>ํ•  ์ผ 3 </li>
		<li><span class="check">&check;</span>ํ•  ์ผ 4 </li>
		<li><span class="check">&check;</span>ํ•  ์ผ 5 </li>
	</ul>


	<script>

		var checks = document.querySelectorAll(".check");

		for(i = 0; i < checks.length; i++) {
			checks[i].addEventListener("click", function() {
				this.style.color = "#ccc";
				this.parentNode.style.color = "#ccc";
				this.parentNode.style.textDecoration="line-through";
			
			});
		}

	</script>
</body>
</html>

 

 

 

* ์—ฐ์Šต๋ฌธ์ œ 2

ํ–‰๊ณผ ์—ด์„ ์ž…๋ ฅํ•˜๋ฉด ํ…Œ์ด๋ธ”์ด ์ถ”๊ฐ€๋˜๋„๋ก 

<!DOCTYPE html>
<html lang="ko">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>์—ฐ์Šต๋ฌธ์ œ 2</title>
	</head>
	<style>
form {
	margin-bottom: 30px;
}

		input[type="text"]{
			width: 30px;
			height: 20px;
			text-align: center;
		}

		button {
			margin-left: 10px;
		}

		table {
			width: 300px;
		}

		table, td {
			border: 1px solid #ccc;
			border-collapse: collapse;
		}

		td {
			padding: 10px;
		}
	</style>
<body>


	<form>
		<input type="text" id = "rCount" value="1">ํ–‰
		<input type ="text" id = "cCount" value="1">์—ด 
		<button onclick="drawTable(); return false;">์ž‘์„ฑ</button>
	</form>

	<div id ="contents">


	</div>

	<script>
		function drawTable() {
			var rCount = document.querySelector("#rCount").value;
			var cCount = document.querySelector("#cCount").value;

			var newTable = document.createElement("table");
			for( i = 0; i< rCount; i++) {
				var newRow = document.createElement("tr");
				for(j = 0; j< cCount; j++) {
					var newCell = document.createElement("td");
					var newText = document.createTextNode(i + ", " + j );

					newCell.appendChild(newText);
					newRow.appendChild(newCell);
				}
				newTable.appendChild(newRow);
			}

			var contents = document.querySelector("#contents");
			contents.appendChild(newTable);
		}

	</script>
</body>
</html>
728x90