1. 程式人生 > >翻頁保存多選框的值

翻頁保存多選框的值

bubuko 若是 false span del mode 復數 eve als

$("input[name=‘checkItem‘]").iCheck({   //初始化iCheck
checkboxClass: icheckbox_flat-blue,
});
$("input[name=‘checkItem‘]").on(ifChanged, function (event) {
if (arr.length == 0 && $(this).is(:checked)) {   //若是首條數據,則不作判斷,直接添加
arr.push($(this).val());
}
else {
flag = false;  //定義一個變量(為false時向數組中添加數據)
for (var i = 0; i < arr.length; i++) {    //遍歷數組 if (arr[i] == $(this).val() && $(this).is(:checked)) {  //選中時判斷: 若選中值與數組中的值重復並且是選中狀態, 則不往數組中添加重復數據, 更改變量 flag = true; break; } else if (arr[i] == $(this).val() && $(this).is(:checked) == false)  //取消選中時判斷 { arr.splice($.inArray($(this
).val(), arr), 1); flag = true; //避免再次添加 break; } } if (!flag) { arr.push($(this).val());   //添加選中項 } } }); if (model.model.List!=null)     { for (var i = 0; i < model.model.List.length; i++) { $("#checkItem_" + model.model.List[i] + "").iCheck(check);  //遍歷選中值,符合項勾選 } }

技術分享圖片

翻頁保存多選框的值