我是 jquery 的新手。我对 jquery 中的选择规则感到困惑。我创建了 3 个问题并希望用户单击答案。颜色的 div 如果正确则变为蓝色,如果错误则变为红色。但是,如果我只是点击第一个问题的正确答案,错误答案的所有颜色也会改变。我应该怎么办?
感谢观看,不胜感激!
$(".correct ").click(function() {
$(this).css('background-color', '#b8daff');
$(".wrong").css('background-color', '#f5c6cb');
});
.correct,
.wrong {
padding: 5px;
text-align: center;
background-color: #b1dfbb;
border: solid 1px #c3c3c3;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>QUESTION</p>
<div class="question">
<div class="d-flex inline">
<div class="w-50 correct">A. Correcrt Answer</div>
<div class="w-50 wrong">B. Wrong answer </div>
</div>
</div>
<p>QUESTION</p>
<div class="question">
<div class="d-flex inline">
<div class="w-50 correct">A. Correcrt Answer</div>
<div class="w-50 wrong">B. Wrong answer </div>
</div>
</div>
<p>QUESTION</p>
<div class="question">
<div class="d-flex inline">
<div class="w-50 correct">A. Correcrt Answer</div>
<div class="w-50 wrong">B. Wrong answer </div>
</div>
</div>
哆啦的时光机
智慧大石
萧十郎
相关分类