zoukankan      html  css  js  c++  java
  • jquery的全选和多选操作

    //全选产品
    $('#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。

  • 相关阅读:
    div弹出层
    经典SQL语句
    sql连接及操作
    给flash加上连接
    在c#中图片原比例缩放
    悬浮提示筐
    拖动板块
    IFrame自适应高度
    SQL语句中的日期计算
    注意Request.Cookies["UserID"]的用法
  • 原文地址:https://www.cnblogs.com/shenwh/p/10330624.html
Copyright © 2011-2022 走看看