I read on many forums that the problem of select and multiselect has been resolved after the beta version of bootstrap 4.
Unfortunately I am unable to display the multiselect as in (bootstrap 3) in (bootstrap 4).
Bootstrap 3 Snippet
$('select').selectpicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/css/bootstrap-select.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/js/bootstrap-select.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<select class="selectpicker" multiple data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
Bootstrap 4 Snippet
$('select').selectpicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<select class="selectpicker" multiple data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
Because the bootstrap-select is a bootstrap component and therefore you need to include it in your code as you did for your V3
NOTE: this component only works in boostrap-4 since version 1.13.0
$('select').selectpicker();
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
<select class="selectpicker" multiple data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
MultiSelect DropDown with checkboxes
<div class="col-md-6">
<div class="depSelectToEdit">
<label>Departments: <input type="text" class="total" value="6 Selected" readonly></label>
<div class="form-control parentChkBox">
<div class="checkbox">
<label><input class="parentChk" type="checkbox" value="All">Select All</label>
</div>
</div>
<div class="form-control multiSelections">
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="Networking" checked>Networking</label>
</div>
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="Billing" checked>Billing</label>
</div>
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="Support" checked>Support</label>
</div>
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="IT" checked>IT</label>
</div>
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="Marketing" checked>Marketing</label>
</div>
<div class="checkbox">
<label><input class="childChk" type="checkbox" value="Management" checked>Management</label>
</div>
</div>
</div>
</div>
Script
// Department selection In EditPopup
$('.depSelectToEdit .parentChk').click(function () {
if ($(this).is(':checked')) {
$(".depSelectToEdit .total").val("");
$(".depSelectToEdit .total").val("Selected " + $('.depSelectToEdit .parentChk').val());
$(".depSelectToEdit .childChk").prop('checked', true);
$('.depSelectToEdit .childChk').click(function () {
var totalchildChk = $(".depSelectToEdit .childChk").length;
if ($(".depSelectToEdit .childChk:checked").length < totalchildChk) {
$('.depSelectToEdit .parentChk').prop('checked', false);
} else
{
$('.depSelectToEdit .parentChk').prop('checked', true);
$(".depSelectToEdit .total").val("Selected " + $('.depSelectToEdit .parentChk').val());
}
});
} else {
$(".depSelectToEdit .childChk").prop('checked', false);
$(".depSelectToEdit .total").val("");
}
});
$('.depSelectToEdit .childChk').click(function () {
$(".depSelectToEdit .total").val('');
$(".depSelectToEdit .childChk").each(function () {
if ($(".depSelectToEdit .childChk:checked").length < 4) {
if ($(this).prop('checked')) {
var childChkfirstValue = $(".depSelectToEdit .total").val();
if (childChkfirstValue == "") {
var allValues = childChkfirstValue + $(this).val();
} else
{
var allValues = childChkfirstValue + ", " + $(this).val();
}
$(".depSelectToEdit .total").val(allValues);
}
} else
{
var count = $('.depSelectToEdit .childChk:checked').length;
$(".depSelectToEdit .total").val(count + " Selected");
}
});
});
来源:https://stackoverflow.com/questions/50895806/bootstrap-4-multiselect-dropdown