简体   繁体   English

如何使用jQuery从多选下拉列表中打印选定的值?

[英]how to print selected values from multiselect dropdown list using jquery?

 <html> <head> <title>Multi-select</title> <link rel="stylesheet" type="text/css" href="bower_components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="bower_components/bootstrap-multiselect/dist/css/bootstrap-multiselect.css"> <script type="text/javascript" src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <script type="text/javascript" src="bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js"></script> </head> <body> <select id="example" multiple="multiple"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <script> $('#example').multiselect({ buttonClass: "btn btn-default", buttonWidth: "140px", }); </script> </body> </html> 

this is my code...i have to print selected values from dropdownlist...how can i use jquery...if i select 1,2,3 options it will print that values 这是我的代码...我必须从下拉列表中打印选定的值...我该如何使用jquery ...如果我选择1,2,3选项它将打印该值

You can use .val() along with select element selector: 您可以将.val()与选择元素选择器一起使用:

When the first element in the collection is a select-multiple (ie, a select element with the multiple attribute set), it returns an array containing the value of each selected option, or null if no options are selected. 当集合中的第一个元素为select-multiple(即具有设置了multi属性的select元素)时,它将返回一个包含每个选定选项的值的数组;如果未选择任何选项,则返回null。

$('#example').val(); 

You can convert this array to CSV using .join() . 您可以使用.join()将此数组转换为CSV。

$( "#myselect option:selected" ).text();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jQuery在标签中显示多选下拉列表的选定文本? - How to display selected text of multiselect dropdown in label using jquery? 使用Knockout.js如何从数组中的多选下拉列表中提取所选项目 - Using Knockout.js how to extract selected items from a multiselect dropdown list in an array 如何从asp.net中的数组中的多选下拉列表中存储选定值的列表? - How to Store List of selected value from multiselect dropdown list in array in asp.net? 我正在使用“ng-multiselect-dropdown”但是当我 select 列表选择的值显示在下拉列表的输入侧 - i am using "ng-multiselect-dropdown" but when i select list selected values is shown in input side of dropdown 如何使用jQuery验证引导多选下拉列表 - How to validate bootstrap multiselect dropdown using jquery 如何使用jQuery在多选下拉菜单中设置值? - How to set value in multiselect dropdown using jQuery? 从jQuery中的数据库中获取多选下拉列表的选定ID值 - get selected id value of multiselect dropdown binds from database in jquery 如何从Jquery中的多选下拉列表中删除选项 - How to remove Options from multiselect dropdown in Jquery 如何在发布/获取中获取多选下拉列表值的所有选定值? - How to get all the selected values of multiselect dropdown value in post/get? 在jquery multiselect下拉列表中设置值 - Set values in jquery multiselect dropdown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM