사용자가 버튼 1, 2 및 3에서 순서대로 클릭합니다. 사용자가 버튼 3을 클릭하면 "congrats"상자가 튀어 나와 제대로 작동합니다.클릭시 특정 버튼의 배경색 변경
사용자가 버튼 1을 클릭하면 해당 버튼의 배경이 회색으로 바뀌지 만 버튼 2와 3은 여전히 파란색이어야합니다. 그런 다음 사용자가 버튼 2를 클릭하면 버튼 1은 이미 회색이고 버튼 3은 여전히 파란색이어야하는 것처럼 회색으로 바뀌어야합니다. 그런 다음 사용자가 버튼 3을 클릭하면 모든 버튼이 회색으로 나타나고 "congrats"상자가 나타납니다.
지금 버튼 3을 클릭하기 전까지는 모두 파란색으로 유지됩니다. 어떻게 변경합니까?
$(document).ready(function() {
$('#button-1').click(function() {
$('#button-2').click(function() {
$('#button-3').click(function() {
$('.button').css({background: 'grey'});
$('#congrat-box').fadeIn(1200);
});
});
});
});
.button {
height: 30px;
width: 30px;
border-radius: 12px;
background: blue;
color: gold;
border: 1px solid white;
box-shadow: 0 0 3px grey;
}
#congrat-box {
background: orange;
font-size: 24px;
line-height: 50px;
padding: 20px;
text-align: center;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<button id="button-1" class="button">1</button>
<button id="button-2" class="button">2</button>
<button id="button-3" class="button">3</button>
<div id="congrat-box">Congrats!!!</div>