Implementation of jquery easyui multi-select drop-down box
Modify the demo instance provided by the official, which is originally a single choice, let her program multiple choices, and complete all the functions of checking and unchecking.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Combo - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Basic Combo</h2>
<p>Click the right arrow button to show drop down panel that can be filled with any content.</p>
<div style="margin:20px 0"></div>
<select id="cc" style="width:150px"></select>
<div id="sp">
<div style="color:#99BBE8;background:#fafafa;padding:5px;">Select a language</div>
<div style="padding:10px">
<input type="checkbox" name="lang" value="01"><span>Java</span><br/>
<input type="checkbox" name="lang" value="02"><span>C#</span><br/>
<input type="checkbox" name="lang" value="03"><span>Ruby</span><br/>
<input type="checkbox" name="lang" value="04"><span>Basic</span><br/>
<input type="checkbox" name="lang" value="05"><span>Fortran</span>
</div>
</div>
<script type="text/javascript">
$(function(){
var s=",";//设定分隔付
$('#cc').combo({
required:true,//是否验证
editable:true,//是否可编辑
multiple:true//可否支持多选
});
$('#sp').appendTo($('#cc').combo('panel'));
$('#sp input').click(function(){
var v = $(this).next('span').text();
if("," == s){//第一次勾选时起作用
s = $(this).next('span').text();
}else if(-1 < s.indexOf(v)){//当去掉勾选时起作用
var n = s.indexOf(v);
var m = s.indexOf(v)+v.length;
if(0 == s.indexOf(v)){//取消第一个点击的勾选
s = s.substring(n+v.length+1,s.length);
}else if(0 < s.indexOf(v) && ((s.indexOf(v) + v.length) < s.length)){//取消非第一个和最后一个的勾选
s = s.substring(0,n) + s.substring(n + v.length+1,s.length);
}else{//取消最后一个的勾选
s = s.substring(0,n-1);
}
if(null == s || "" == s){
//回调自己
}
}else{
s = s + "," + $(this).next('span').text();//将勾选各值拼接
}
$('#cc').combo('setValue', s).combo('setText', s).combo('showPanel');//将值赋值给文本框并在文本里显示出来
});
});
</script>
</body>
</html>
https://www.cnblogs.com/lanjianqing/p/4596026.html