引用文件:javascript
<link rel="stylesheet" type="text/css" href="../jquery.multiselect.css" />css
<link rel="stylesheet" type="text/css" href="assets/style.css" />java
<link rel="stylesheet" type="text/css" href="assets/prettify.css" />jquery
<link rel="stylesheet" type="text/css" href="../../jquery-ui-1.11.4/jquery-ui-1.11.4/jquery-ui.css" />ui
<script type="text/javascript" src="../../jquery/jquery-1.11.1.js"></script>spa
<script type="text/javascript" src="../../jquery-ui-1.11.4/jquery-ui-1.11.4/jquery-ui.js"></script>blog
<script type="text/javascript" src="../src/jquery.multiselect.js"></script>ip
<script type="text/javascript" src="assets/prettify.js"></script>get
HTML代碼:input
<select id="sel" multiple style="width:100px">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
<option value="7">Option 7</option>
</select>
<input type='button' onclick='setValue()' value='賦值'/>
<input type='button' onclick='getValue()' value='取值'/>
初始化:
$(function(){
$("#sel").multiselect({
selectedList: 4,
noneSelectedText:'請選擇'
});
});
賦值:
function setValue(){
$("#sel").val([2,3]);
$("#sel").multiselect('refresh');
};
取值:
function getValue(){
var v=$("#sel").val();
console.log(v);
};