获取table 多选框选中行数的两种方法对比

    $(document).ready(function(){
            $('input:checkbox[name="supplyCheckBox"]').each(function(i){
                
                $(this).click(function(){
                    // 复选框选中个数
                    var checkedSize = $('input:checkbox[name="supplyCheckBox"][ checked]').length;
                    // 检查是否超过3个选中
                    if (checkedSize > 1) {
                        alert("只能选择一个报价信息!");
                        
                        if ($(this).is(':checked')) {
                            $(this).parent().removeClass("checked");
                            $(this).attr("checked", false);
                        }else {
                            $(this).parent().addClass("checked");
                            $(this).attr("checked", true);
                        }
                        
                        return;
                    }
                    
                })
            });
            
            
        });    
        
        $('#quoteButton').bind("click",function(e){
                e.preventDefault();
                
                // 复选框选中个数
                var checkbox = document.getElementsByName("supplyCheckBox");
                var checkedSize = 0;  //初始化一下number
                var quoteNo = ''; //记录所选数据的id
                if(checkbox.length != 0)  //判断条件是当选择的个数不为0时
                {
                    for( i = 0; i < checkbox.length; i ++)  //循环遍历复选框
                    {
                        if (checkbox[i].checked == true)  //如果[i]个复选框为选中状态
                        {
                            checkedSize ++;  //累加所选的个数
                            quoteNo=checkbox[i].defaultValue;
                        }
                    }
                }
                // 检查是否超过3个选中
                if (checkedSize < 1) {
                    alert("请选择唯一的中标对象!");
                    return;
                }
                if (checkedSize == 1) {
                location.href="${contextPath}/systems/srm/purchase/iq/chooseQuote.html?quoteNo=" + quoteNo;
                }
            });   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值