最大1つまでチェックするように制限する一連のチェックボックスがあります。選択肢を変更する必要がある場合は、最初にチェックされたものをチェックする必要がありますが、最大限を1にする必要があります。 ここに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を提供します。
はこのようなものですか? –
'選択を変更する必要がある場合、最初にチェックされたものをチェックする必要がありますが、最大限は1にする必要があります。' ' –
@MayankPandey HTMLを追加 – Lara