1,下载插件
https://github.com/ehynds/jquery-ui-multiselect-widget
2,效果:
3.引用文件:
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery_multiselect/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery_multiselect/style.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery_multiselect/prettify.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery_multiselect/jquery-ui.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery_multiselect/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery_multiselect/jquery.multiselect.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery_multiselect/prettify.js"></script>
4. 标签:
<select name="levelCondition" id="levelCondition" multiple="multiple" style="width:100px">
<option value="STD">标准</option>
<option value="MIN">迷你</option>
<option value="VIP">尊贵</option>
<option value="GVIP">VIP白金</option>
</select>
5.js
$(document).ready(function (){
$("select[multiple]").multiselect({
selectedList: 4
});
//初始化默认选中已有的选项,sceneIdList是要默认选中的值
var sceneIdArr ='<s:property value="levelConditionStr"/>'.split(",");
$('#levelCondition option').each(function (i, content) {
// alert(i+"***"+content.value);
if ($.inArray($.trim(content.value), sceneIdArr) >= 0) {
this.selected = true;
}
});
//设置选中值后,需要刷新select控件
$("#levelCondition").multiselect('refresh');
});