<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>
这是我的代码...我必须从下拉列表中打印选定的值...我该如何使用jquery ...如果我选择1,2,3选项,它将打印该值
您可以将其.val()
与select元素选择器一起使用:
当集合中的第一个元素为select-multiple(即具有设置了multi属性的select元素)时,它将返回一个包含每个选定选项的值的数组;如果未选择任何选项,则返回null。
$('#example').val();
您可以使用将数组转换为CSV .join()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句