1.当前需求是,获取一个指定样式(class)下的所有选中的复选框的值,页面如下
代码如下:
<dl class="permission-list">
<dt>
<label>
<input type="checkbox" id="user-Character-0" name="user-Character-0" value="22">
菜单管理</label>
</dt>
<dd>
<label class="permission-list2">
<input type="checkbox" id="user-Character-0-0" name="user-Character-0-0" value="24">
菜单列表</label>
<label class="permission-list2">
<input type="checkbox" id="user-Character-0-0" name="user-Character-0-0" value="23">
添加菜单</label>
</dd>
</dl>
<dl class="permission-list">
<dt>
<label>
<input type="checkbox" id="user-Character-0" name="user-Character-0" value="19">
员工管理</label>
</dt>
<dd>
<label class="permission-list2">
<input type="checkbox" id="user-Character-0-0" name="user-Character-0-0" value="25">
test</label>
<label class="permission-list2">
<input type="checkbox" id="user-Character-0-0" name="user-Character-0-0" value="21">
员工列表</label>
<label class="permission-list2">
<input type="checkbox" id="user-Character-0-0" name="user-Character-0-0" value="20">
添加员工</label>
</dd>
</dl>
jquery代码如下
$('#admin-role-save').click(function(){
var spCodesTemp = "";
$('.permission-list input:checkbox:checked').each(function(i){
if(0==i){
spCodesTemp = $(this).val();
}else{
spCodesTemp += (","+$(this).val());
}
});
layer.msg(spCodesTemp,{icon:1,time:1000});
});