최대 하나까지 체크하도록 제한하려는 체크 박스 세트가 있습니다. 선택 사항을 변경해야하는 경우 먼저 확인 된 항목을 선택 취소해야하지만 최대 한도는 하나 여야합니다. 다음은 jquery 코드입니다. 여기 체크 박스 체크 이벤트가 방지되지 않습니다.
$('#ReportRow').on('click', 'input[type="checkbox"]', (function (event) {
alert("Hi");
var checkedReportValues = $('#ReportRow input:checkbox:checked').map(function() {
return this.value;
}).get();
if ($("#ReportRow input:checkbox:checked").length > 1) {
return false;
}
alert(checkedReportValues);
})
);
은, 위의 코드를 검사 할 단 하나의 체크 박스를 제한하고 있지만 다른를 확인하려고 할 때, 그들은 먼저 확인되고 있으며, 다음을 선택하지. 내가 잘못하고있는 곳?
여기에 동적으로 생성 된 HTML이 있습니다.
//Add Code to Create CheckBox dynamically by accessing data from Ajax for the application selected above
var Reports = " User, Admin, Detail, Summary";
var arrReportscheckBoxItems = Reports.split(',');
var reportscheckBoxhtml = ''
for (var i = 0; i < arrReportscheckBoxItems.length; i++) {
reportscheckBoxhtml += ' <label style="font-weight: 600; color: #00467f !important;"><input type="checkbox" value=' + arrReportscheckBoxItems[i] + '>' + arrReportscheckBoxItems[i] + '</label>';
}
//Add Submit button here
reportscheckBoxhtml += ' <button type="button" id="SubmitReport" class="btn btn-primary">Submit</button>';
$('#ReportRow').html(reportscheckBoxhtml);
가 당신의 HTML을 제공합니다
는 다음과 같이합니까? –
'선택 사항을 변경해야한다면 처음 체크 한 것들은 체크하지 말아야하지만 최대 한도는 하나 여야합니다.'use ' –
@MayankPandey HTML을 추가했습니다. – Lara