[英]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.