全选的,部分选。checkbox,显示隐藏列的js代码

    <script type="text/javascript">

                    /*套餐迁转-显示列表*/
                    function checklist() {
                        var listNos = $("input[name='listNo']:checked").serialize();
                        console.log("=================" + listNos);
                        layer.confirm('确认要保存吗?', function (index) {
                            $.ajax({
                                type: "POST",
                                url: "tohersystem/common/checklistsave.do",
                                data: listNos + "&type=" +${type},
                                async: true,
                                dataType: "text",
                                success: function (data) {
                                    if (data == "success") {
                                        layer.msg('已保存!', {icon: 1, time: 1000});
                                        setTimeout("parent.$('#btn-refresh').click()", 1000);
                                    } else {
                                        layer.msg("保存失败,请至少选择一项", { time: 3000});
                                    }
                                     
                                }
                            });
                        });
                    }

                    /*全选*/
                    $("#allChecked").on("click", function () {
                        $("input[name='listNo']").prop("checked", $("#allChecked").prop("checked"));
                    });


                    $(function () {
                        var listNo = "${listNo}";
                        if (listNo == "") {
                            $("input[type='checkbox']").each(function () {
                                $(this).attr("checked", true);
                            });
                        } else {
                            var arrayNo = new Array();
                            var arrayNo = listNo.split(",");
                            //先查找所有的checkbox
                            $("input[type='checkbox']").each(function () {
                                var vlaue = $(this).val();
                                for (i = 0; i < arrayNo.length; i++) {
                                    if (vlaue == arrayNo[i]) {
                                        $(this).attr("checked", true);
                                    }
                                }
                            })
                        }
                    })
        </script>

  

posted @ 2017-08-04 21:08  来自IT国的猴子  阅读(291)  评论(0编辑  收藏  举报