layui前端框架的使用場景:公司後臺管理系統
問題點: 如何判斷是否選中複選框、獲取它選中的值、並獲取選中了幾個複選框
常規的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"