您的位置:首页 > 其它

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

2014-08-19 14:11 337 查看
    $(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;

                }

            });   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: