问题点: 如何判断是否选中复选框、获取它选中的值、并获取选中了几个复选框
常规的js方法中判断:
$("input:checkbox[name='tagid']:checked").each(function(){
// arr[i] = $(this).val();
tagids = $(this).val()+"," + tagids ;
});
无法正确获取。
解决办法:
//laui的复选框检测选择的个数,并限制其个数
form.on('checkbox(tagid)',function(data){
console.log(data)
if ($("input[name='tagid']:checked").length>5){
//将选中的全部取消
//$("input[name='level']:checked").removeAttr("checked");
//$(this).checked = false;
$(this).prop("checked", false);
form.render('checkbox');
layer.msg("最多只能选择5个标签", {
time : 3000,
icon : 10
});
}
});
tagid指的是:lay-filter="tagid"
如果您觉得本文的内容对您的学习有所帮助:
关键字:
jQuery