라디오가 많이 있어요. 다음은 이들을위한 코드입니다.
<div class="question">18 years old or older?</div>
<div class="radios">
<input type="radio" name="age" value="yes"> Yes
<input type="radio" name="age" value="no"> No
<div class="tooltip"><span>Sorry, you must be 18 years old or older.</span></div>
</div>
<div style="clear: both;"></div>
<div class="question">Earn $1,600 or more each month?</div>
<div class="radios">
<input type="radio" name="earn" value="yes"> Yes
<input type="radio" name="earn" value="no"> No
<div class="tooltip"><span>Sorry, you must earn $1,600 or more each month.</span></div>
</div>
<div style="clear: both;"></div>
<div class="question">Stable in your job and residence?</div>
<div class="radios">
<input type="radio" name="stable" value="yes"> Yes
<input type="radio" name="stable" value="no"> No
<div class="tooltip"><span>Sorry, you must be stable in your job and residence.</span></div>
</div>
<div style="clear: both;"></div>
<div class="question">No reposessions within 1 year?</div>
<div class="radios">
<input type="radio" name="repo" value="yes"> Yes
<input type="radio" name="repo" value="no"> No
<div class="tooltip"><span>Sorry, you must have no reposessions within 1 year.</span></div>
</div>
<div style="clear: both;"></div>
누군가이 라디오를 클릭하면 모든 라디오 값이 "예"인지 아닌지 확인하고 싶습니다.
예인 경우 "모두 예!"라고 경고합니다.
작동하지 않는 내 코드는 다음과 같습니다.
$('.radios input').mousedown(function () {
if ($(this).val() == 'no')
$(this).closest('.radios').find('.tooltip').show();
else
$(this).closest('.radios').find('.tooltip').hide();
$yescount = 0;
$('.radios input').each(function () {
if ($(this).val() == 'yes')
$yescount += 1;
});
if ($yescount == 4)
alert('all yes');
});
어떤 도움이라도 좋을 것입니다.
모든 라디오가 '예'로 설정되어 있지 않아도 경고하는 것 같습니다.
사용하다:
$('.radios input').click(function () {
if($('input[type=radio][value="yes"]:checked').length==$('input[type=radio][value="yes"]').length) alert('yes');
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다