-
카테고리
-
세부 분야
웹 개발
-
해결 여부
미해결
별점주기 첫번째에서 nextAll이 적용안됩니다.
23.04.21 15:30 작성 조회수 188
1
prevAll속성은 잘 들어가지는데
그 다음에 넣은 nextAll 속성이 동작을 안하네요..
코드도 다 똑같이 넣고 오타도 없는데 어디를 수정해야하나요...?
답변을 작성해보세요.
1
gm021716
질문자2023.04.24
<!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>별점주기</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".stars .fa-star").click(function(){
$(this).addClass("active");
$(this).prevAll().addClass("active");
$(this).nextAll().removeClass("active");
let num = $(this).index();
let starRate = num + 1;
if(starRate == 1){
$(".print").text("별로에요");
}
else if(starRate == 2){
$(".print").text("적당해요");
}
else if(starRate == 3){
$(".print").text("좋아요");
}
else if(starRate == 4){
$(".print").text("괜찮아요");
}
else{
$(".print").text("아주 좋아요");
}
});
})
</script>
<style>
@import url("https://fonts.googleapis.com/css?family=Noto+Sans+KR:300,400,500,700,900&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Noto Sans KR", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.star-rating {
background-color: #333;
width: 300px;
text-align: center;
border-radius: 5px;
padding: 5px;
}
.star-rating div {
float: left;
width: 50%;
}
.stars {}
.stars .fa-star {
font-size: 18px;
cursor: pointer;
}
.stars .fa-star.active {
color: yellow;
text-shadow: 0 0 5px yellow;
}
.print {
color: #fff;
}
</style>
</head>
<body>
<div class="star-rating">
<div class="stars">
<i class="fa-solid fa-star"></i>
<i class="fa-solid fa-star"></i>
<i class="fa-solid fa-star"></i>
<i class="fa-solid fa-star"></i>
<i class="fa-solid fa-star"></i>
</div>
<div class="print">
별점 주실거죠? ㅎㅎ
</div>
</div>
</body>
</html>
0
코딩웍스(Coding Works)
지식공유자2023.04.25
폰트어썸 링크에서 2가지가 링크되었는데 하나를 주석하니까 문제없네요.
제가 폰트어썸을 요즘 쓰질 않아서 왜 그런지 이유는 잘 모르겠네요. 아래처럼 하시면 됩니다.
답변 2