728x90
반응형


<!DOCTYPE html>
<html lang="en">
<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">
<script src="../js/jquery.min.js"></script>
<title>Counter</title>
</head>
<style>
html,body{
height:100%;
overflow:hidden;
}
#wrap{
width:100%;
height:100%;
background-color: rgb(209, 246, 234);
display:flex;
align-items: center;
}
#counter_box{
width:600px;
height:500px;
/* background-color: red; */
}
#counter{
font-size:30px;
text-align: center;
}
#num{
text-align: center;
font-size:25px;
}
#decrease{
display:inline-block;
width:100px;
height:50px;
color: black;
border:2px solid black;
text-align: center;
padding-top: 12px;
box-sizing: border-box;
margin-left:150px;
border-radius: 10px;
}
#reset{
display:inline-block;
width:100px;
height:50px;
color:black;
border:2px solid black;
text-align: center;
padding-top: 12px;
box-sizing: border-box;
border-radius: 10px;
}
#increase{
display:inline-block;
width:100px;
height:50px;
color:black;
border:2px solid black;
text-align: center;
padding-top: 12px;
box-sizing: border-box;
border-radius: 10px;
}
</style>
<script>
$(function(){
var num = 0
$("#decrease").click(function(){
num--
if(num>0) {
document.getElementById("num").innerHTML='<span style="color:blue">'+num+"</span>"
} else if(num==0){
document.getElementById("num").innerHTML='<span style="color:black">'+num+"</span>"
} else if(num<0) {
document.getElementById("num").innerHTML='<span style="color:red">'+num+"</span>"
}
})
$("#reset").click(function(){
num = 0
document.getElementById("num").innerText=num
})
$("#increase").click(function(){
num++
if(num>0) {
document.getElementById("num").innerHTML='<span style="color:blue">'+num+"</span>"
} else if(num==0){
document.getElementById("num").innerHTML='<span style="color:black">'+num+"</span>"
} else if(num<0) {
document.getElementById("num").innerHTML='<span style="color:red">'+num+"</span>"
}
})
})
</script>
<body>
<div id="wrap">
<div id="counter_box">
<div id="counter">
<b>Counter</b>
</div>
<div id="num">
0
</div>
<div id="btn_box">
<div id="decrease">
decrease
</div>
<div id="reset">
reset
</div>
<div id="increase">
increase
</div>
</div>
</div>
</div>
</body>
</html>
1. num을 0으로 초기셋팅
2. decrease 시 num-- , increase시 num++ , reset시 num == 0 으로 num값 컨트롤
3. 각 함수에 if로 num값의 음수,0,양수 값에 따른 색상 부여
728x90
반응형
'HTML+CSS(실습)' 카테고리의 다른 글
2023-05-03(화) 미니프로젝트(sideNav) (0) | 2023.05.02 |
---|---|
★2023-05-02(화) 미니프로젝트(headNav) (0) | 2023.05.02 |
2023-05-02(화) 미니프로젝트(Random Color Page) (0) | 2023.05.02 |
★2023-04-26(수) ToDoList(Re) (0) | 2023.04.26 |
2023-04-25(화) 미세먼지 api 실습 (0) | 2023.04.25 |