Home > Article > Backend Development > bootstrap-multiselect multi-select example code
Usage:
The first step is to reference the style and related JS
<link rel="stylesheet" href="css/bootstrap.min.css?1.1.11" type="text/css"/> <script type="text/javascript" src="js/jquery.min.js?1.1.11"></script> <script type="text/javascript" src="js/bootstrap.min.js?1.1.11"></script> <!-- Include the plugin's CSS and JS: --> <script type="text/javascript" src="js/bootstrap-multiselect.js?1.1.11"></script> <link rel="stylesheet" href="css/bootstrap-multiselect.css?1.1.11" type="text/css"/>
The second step is to construct the Selection (note the need Set the multiple attribute, otherwise it will still be in radio selection mode, multiple="multiple" )
<!-- Build your select: --> <select class="multiselect" multiple="multiple"> <option value="cheese">Cheese</option> <option value="tomatoes">Tomatoes</option> <option value="mozarella">Mozzarella</option> <option value="mushrooms">Mushrooms</option> <option value="pepperoni">Pepperoni</option> <option value="onions">Onions</option> </select>
The third step is to initialize the plug-in:
<script type="text/javascript"> $(document).ready(function() { $('.multiselect').multiselect(); }); </script>
Commonly used Method:
select
$('#cid').multiselect('select', arr[i]); Set the selected item for the control
Get the value
$('#cid').val();Get all selected values of the control
The above is the detailed content of bootstrap-multiselect multi-select example code. For more information, please follow other related articles on the PHP Chinese website!