728x90
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#container {
border: 1px solid black;
line-height: 40px;
width: 500px;
margin: 50px auto;
}
h1 {
text-align: center;
}
ul {
list-style-type: none;
}
li {
font-size: 1.2em;
}
.check{
padding-right: 20px;
}
</style>
</head>
<body>
<div id="container">
<h1>할 일 목록</h1>
<ul>
<li class="check"><span>✓</span> 할 일 2</li>
<li class="check"><span>✓</span> 할 일 3</li>
<li class="check"><span>✓</span> 할 일 1</li>
<li class="check"><span>✓</span> 할 일 4</li>
<li class="check"><span>✓</span> 할 일 5</li>
</ul>
</div>
<script>
var choice1 = document.querySelectorAll(".check");
var flag = false;
for(var i = 0; i < choice1.length; i++){
choice1[i].addEventListener("click", chageText);
}
function chageText(){
if(flag === false) {
this.style.color="#ccc";
this.style.color = "#ccc";
this.style.textDecoration="line-through";
flag = true; // flag 속성 true로 반환
}else {
this.style.color="";
this.style.color = "";
this.style.textDecoration="";
flag = false; // flag 속성 false로 반환
}
}
</script>
</body>
</html>728x90
'JAVA > 연습장!' 카테고리의 다른 글
| Vue.js 연습장! (0) | 2022.12.28 |
|---|---|
| 행과 열 입력받아 표 그리는 프로그램작성 (1) | 2022.12.20 |
| 조건문 연습문제 (0) | 2022.12.14 |
| 클래스 , class 연습문제! (0) | 2022.12.13 |
| 메소드, 연습 - java (0) | 2022.12.12 |