다른 ID의 두 개의 확인란과 다른 텍스트 상자와 다른 div
4 개의 라디오 버튼으로 구성된 라디오 그룹 이있는 페이지가 있습니다 div
. 내가 달성하려는 것은 다음과 같습니다.
사용자가 첫 번째 확인란을 선택하면 다음이 발생합니다.
사용자가 첫 번째 확인란을 선택 취소하면 위 단계를 다시 확인해야합니다.
사용자가 두 번째 확인란을 선택하면 다음이 발생합니다.
사용자가 두 번째 확인란을 선택 취소하면 위 단계를 다시 수행해야합니다.
나는 다음 코드를 생각 해냈다.
$("#firstCheckBox").on("change", function () {
if ($(this).is(":checked")) {
$('#secondCheckBox').prop('disabled', true);
$('#spinner').val('0');
$('#spinner').prop('readonly', true);
$('#radio_id:first').prop('checked', true);
$('#radio_id:not(:checked)').hide();
} else {
$('#secondCheckBox').prop('disabled', false);
$('#spinner').val('');
$('#spinner').prop('readonly', false);
$('#radio_id:first').prop('checked', false);
$('#radio_id:not(:checked)').show();
}
});
$("#secondCheckBox").on("change", function () {
if ($(this).is(":checked")) {
$('#firstCheckBox').prop('disabled', true);
$('#spinner').val('1');
$('#spinner').prop('readonly', true);
$('#radio_id:first').prop('checked', true);
$('#radio_id:not(:checked)').hide();
} else {
$('#firstCheckBox').prop('disabled', false);
$('#spinner').val('');
$('#spinner').prop('readonly', false);
$('#radio_id:first').prop('checked', false);
$('#radio_id:not(:checked)').show();
}
});
그래서 제 질문은 더 나은 방법이 있습니까? 아니면 올바른 길을 가고 있습니까?
이 같은:
var $targetCheckBoxes = $("#firstCheckBox,#secondCheckBox");
$targetCheckBoxes.change(function () {
var isChecked = this.checked;
var currentElement = this;
$targetCheckBoxes.filter(function(){
return this.id != currentElement.id;
}).prop('disabled', isChecked );
$('#spinner').val( isChecked ? this.value : '');
$('#spinner').prop('readonly', isChecked);
$('#radio_id').toggle(isChecked).prop('checked', isChecked );
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다