目前我有一个添加了一些jscript的列表,这个列表从SOLR
获取类别。我的问题是,如何从我的选择中获得更多项目?
<script src="jquery-1.8.0.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var cat= ["C"];
$("#cat").select2({
data: cat
});
});
</script>
<select name="cat[]" id="cat" >
<option value="all">Categories</option>
<option value="all">All</option>
<option value="HI">Hawaii</option>
<option value="C">Hawaji</option>
</select>
答案 0 :(得分:0)
你可以这样做
<script type="text/javascript">
$(document).ready(function(){
var keys = [];
$("#countries").change(function(event){
var thi = $(this).val();
keys.push(thi);
alert('Array length: '+keys.length);
});
});
<select name="countries" id="countries" multiple>
<option value="">Select ...</option>
<option value="EN">England</option>
<option value="GR">Greece</option>
<option value="US">USA</option>
<option value="IT">Italy</option>
</select>
答案 1 :(得分:0)
如果您不需要添加到数组并希望使用表单操作发送值,则只需为选择列表设置multiple属性:
<select name="cat" id="cat" multiple >
<option value="all">Categories</option>
<option value="all">All</option>
<option value="HI">Hawaii</option>
<option value="C">Hawaji</option>
</select>
示例:http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple