shenwh

//全选产品
$(\'#checkAll\').click(function() {
$(this).prop(\'checked\',!$(this).prop(\'checked\'));
if($(this).prop(\'checked\')) {
$(this).prop(\'checked\',false);
$(\'#getProduct input\').each(function(index,item) {
$(item).prop(\'checked\',false)
})
}else {
$(this).prop(\'checked\',true);
$(\'#getProduct input\').each(function(index,item) {
$(item).prop(\'checked\',true)
});
};
});

//二分查找
function binarySearch(arr,target) {
var l = 0,r = arr.length-1;
while(l <= r) {
var mid = (l+r)/2;
if(arr[mid] == target) {
return mid
}else if(arr[mid] < target) {
l = mid+1
}else {
r = mid-1
}
};
return -1;
}
//多选产品
$(\'#getProduct input\').each(function(index,item) {
$(item).click(function() {
var count = 0;
if (!$(this).prop("checked")) {
$(this).prop("checked", false);
} else {
$(this).prop("checked", true);
};
$(\'#getProduct input\').each(function(index,item) {
if($(item).prop(\'checked\')) {
count ++;
}else {
count --;
};
});
if(count == $(\'#getProduct input\').length) {
$(\'#checkAll\').prop(\'checked\',true)
}else {
$(\'#checkAll\').prop(\'checked\',false)
};
})
})

其中#checkAll是全选按钮的id,#getProduct input是tbody中的所有类型为checkbox的input。

分类:

技术点:

相关文章: