제 스크립트에 약간의 문제가 있습니다.jQuery는 .each 함수보다 먼저 클래스를 제거하지 않습니다.
스크립트는 작동하는 것처럼 보이지만 선택한 클래스를 추가 할 때마다 나타납니다. 그것은 onclick 전에 그것을 재설정하지만, 클래스는 그것을 제거하지 않습니다. 무엇이 문제가 될 수 있습니까? 컬렉션에서 .payment 클래스의
하나 개의 요소는 .selected 클래스
$(".payment").each(function() { \t
$(".payment").removeClass("selected");
$(this).on("click", function() {
$(this).addClass("selected");
$(this).find('input[type="radio"]').prop("checked", true);
});
});
.selected { \t
background: #eaeaea;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="payment">
\t <input type="radio" /> example
</div>
<div class="payment">
\t <input type="radio" /> of my
</div>
<div class="payment">
\t <input type="radio" /> problem
</div>
sauero을 모든 라디오 버튼이 선택하고자 했는가? 또는 클릭 한 사람 만? 두 번째 것을 원하면 그 대답을 확인하십시오 –