判断多个复选框被选中状态(两种方式)

$(document).on("click","#historya",function(){
        //创建数组
        var checkedList = new Array();
        //两种判断type=checkbox方式
//第一种.....................................
//        if(checkedList.length == 0){
//            $("#famessage").text("请选择需要填写发票票号的商品").css({"color":"red","margin-left":"20px"});
//        }
//        $("input[name='subChk']:checked").each(function(i) {
//            $("#famessage").text("");
//             $(".billwrite").css('display','block');
//             //获取checked的id
//             var checkid = $(this).attr("data-fa");
//             checkedList.push(checkid);

//第二种.........................................

//遍历每个input对应的class名然后进行判断
         $(".hisselect").each(function(i) {
//            判断input=checkbox被选中
//             console.log($(this));
             if($(this).is(':checked')){
                     $("#famessage").text("");
                     $(".billwrite").css('display','block');
                     //获取checked的id
                     checkedList.push($(this).attr("data-fa"));
               }else{
                   $("#famessage").text("请选择需要填写发票票号的商品").css({"color":"red","margin-left":"20px"});
               }
         });

        //函数调用
         subfamsg(checkedList);
    })

你可能感兴趣的:(前端非框架常用)