ラジオボタンで5つの役割があります。したがって、roleA、Bが選択されたユーザーの場合、自動的にすべての値が選択されますが、roleCをチェックすると1つの値しか選択できません.RoleD、Eは、必要な数だけ値を選択できます。ただし、アップ。したがって、ロールCは1つの値を選択することのみが許可されますが、ロールE、Cに戻ると、チェックボックスはロールCとして選択されたまま固定されます。私は何が間違っているのか分かりません。助けて!複数選択ブートストラッププラグインを使用して特定のラジオボタンを選択しても使用しない場合は、選択した値を1に制限しようと何度も試みました。
here is the code with jsFiddle https://jsfiddle.net/1ar5g43g/1/
$(ドキュメント).ready(関数(){
$( "#入力ユーザー市場")複数選択( '選択'、文字列|アレイ、{ includeSelectAllOption:。本当、 enableFiltering:真、 nonSelectedText: 'オプションをチェックしてください!' });
$('.checks').change(
function() {
var radioButton = $('.checks:checked').val();
if (radioButton == "RoleA" || radioButton == "RoleB") {
$('#input-user-market').multiselect('refresh', false);
$('#input-user-market').multiselect('selectAll', false);
$('#input-user-market').multiselect('updateButtonText', false);
} else
if (radioButton == "RoleC") {
$("#input-user-market").on("change", function() {
var selectedOptions = $('#input-user-market option:selected');
if ((selectedOptions.length = 1) && (selectedOptions.length = 1)) {
// Disable all other checkboxes.
var nonSelectedOptions = $('#input-user-market option').filter(function() {
return !$(this).is(':selected');
});
var dropdown = $('#input-user-market').siblings('.multiselect-container');
nonSelectedOptions.each(function() {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');
});
}
else if (selectedOptions.length <= 1) {
var SelectedOptions = $('#input-user-market option').filter(function() {
console.log("1 select")
return $(this).is(':selected');
});
var dropdown = $('#input-user-market').siblings('.multiselect-container');
SelectedOptions.each(function() {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');
});
}
else {
// Enable all checkboxes.
var dropdown = $('#input-user-market').siblings('.multiselect-container');
$('#input-user-market option').each(function() {
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', false);
input.parent('li').addClass('disabled');
});
}
});
}
else {
$('#input-user-market option:selected').each(function() {
$(this).prop('selected', false);
});
$('#input-user-market').multiselect('refresh');
}
}
)
});
https://jsfiddle.net/1ar5g43g/1/
また、HTMLコードを追加してください。これは、より良い解決策を提供するのに役立ちます。 – Shiladitya
@Shiladitya非常にまもなく!ありがとう –
@Shiladityaここに行く! https://jsfiddle.net/1ar5g43g/1/ –