简体   繁体   中英

How to select multiple values from dropdown?I am using Bootstrap css version 3

I need to select the multiple values from the dropdown.I am using bootstrap css.

This is my dropdown code:

  <select multiple class="dropdown-menu">
        <option value="monday">Monday</option>
        <option value="tuesday">Tuesday</option>
        <option value="wednesday">Wednesday</option>
        <option value="thursday">Thursday</option>
        <option value="friday">Friday</option>
        <option value="saturday">Saturday</option>
        <option value="sunday">Sunday</option>
    </select>

By using the above code i can select multiple options by using CTRL key,but i don't want use ctrl key and i need to select multiple values.

Is it possible to do that with jquery,javascript?

One more thing like Can i select not more than two or three values is it possible?

Many thanks in advance....

This is one way to do without ctrl click.

 $('option').mousedown(function(e) { e.preventDefault(); $(this).prop('selected', $(this).prop('selected') ? false : true); alert($("#mySelect :selected").length);//select option selected count //if($("#mySelect :selected").length==2) //some stuff return false; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select multiple="multiple" id="mySelect"> <option id="1">Option</option> <option id="2">Option</option> <option id="3">Option</option> <option id="4">Option</option> </select> 

See this link.

$('.dropdown-menu option').mousedown(function(e) {
    e.preventDefault();
    $(this).prop('selected', !$(this).prop('selected'));
    return false;
});

您可以将插件用于“ Multiselect” /“ chosen”之类的下拉列表。1. http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/ 2. https://harvesthq.github.io/选择/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM