欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jqGrid增加时--判断开始日期与结束日期(实例解析)

程序员文章站 2023-11-12 18:54:58
代码如下: $("#btnaddsavetestsubject").click(function () {      &nbs...

代码如下:


$("#btnaddsavetestsubject").click(function () {
        //增加时的验证,保存
        jquery.validator.addmethod("admissionbatch", function (value, element) {
            return this.optional(element) || value != 0;
        }, "请选择招生批次");
        jquery.validator.addmethod("educationlevel", function (value, element) {
            return this.optional(element) || value != 0;
        }, "请选择学历层次");
        jquery.validator.addmethod("professionalproperty", function (value, element) {
            return this.optional(element) || value != 0;
        }, "请选择专业性质");
        $("#addentrancetestsubjectfrom").validate({
            event: "blur",
            debug: true,
            ignore: ":hidden",
            errorelement: "p",
            wrapper: "p",
            errorplacement: function (error, element) {
                error.addclass('message');
                error.appendto(element.parent());
            },
            rules: {
                "etsadd_admissionbatch": {
                    required: true,
                    admissionbatch: true
                },
                "etsadd_educationlevel": {
                    required: true,
                    educationlevel: true
                },
                "etsadd_professionalproperty": {
                    required: true,
                    professionalproperty: true
                }
            },
            messages: {
                "etsadd_admissionbatch": {
                    required: "请选择招生批次",
                    admissionbatch: "请选择招生批次"
                },
                "etsadd_educationlevel": {
                    required: "请选择学历类型",
                    educationlevel: "请选择学历类型"
                },
                "etsadd_professionalproperty": {
                    required: "请选择专业性质",
                    professionalproperty: "请选择专业性质"
                }
            },
            submithandler: function (form) {
                var idarray = jquery("#testsubjectgrid").jqgrid('getgridparam', 'selarrrow'); //获取测试科目选中的行 
                if (idarray == null || idarray == "") {
                    jalert("请选择测试科目!", "提示信息");
     &nnbsp;              return;
                }
                for (var i = 0; i < idarray.length; i++) {
                    if ($("#exam_begintime_" + idarray[i]).val() == "") {
                        jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "的开始时间不能为空!", "提示信息");
                        return;
                    }
                    if ($("#exam_endtime_" + idarray[i]).val() == "") {
                        jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "的结束时间不能为空!", "提示信息");
                        return;
                    }
                    var reg_ymd = /^([/d]{4})-([/d]{1,2})-([/d]{1,2})$/; //校验日期的正则
                    begindata = $("#exam_begintime_" + idarray[i]).val();
                    enddata = $("#exam_endtime_" + idarray[i]).val();
                    var arr_dt1, arr_dt2;
                    arr_dt1 = begindata.match(reg_ymd);
                    arr_dt2 = enddata.match(reg_ymd);
                    begindata = new date(arr_dt1[1] + "/" + arr_dt1[2] + "/" + arr_dt1[3]);
                    enddata = new date(arr_dt2[1] + "/" + arr_dt2[2] + "/" + arr_dt2[3]);
                    if (begindata > enddata) {
                        jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "开始时间不能大于结束日期!", "提示信息");
                        return;
                    }
                    if ($("#exam_turn_" + idarray[i]).val() == "") {
                        jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "的考试场次不能为空!", "提示信息");
                        return;
                    }
                    if ($("#exam_turn_" + idarray[i]).val() != "") {
                        var re = /^[-/+]?/d+(/./d+)?$/;
                        var nubmer = $("#exam_turn_" + idarray[i]).val();
                        if (!re.test(nubmer)) {
                            jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "的考试场次必须为数字!", "提示信息");
                            return false;
                        }
                        if ($("#exam_turn_" + idarray[i]).val().length > 8) {
                            jalert("测试科目" + jquery("#testsubjectgrid").jqgrid("getcell", idarray[i], "display_content") + "的考试场次不能大于8位数字!", "提示信息");
                            return;
                        }
                    }
                }
                if ($("#addentrancetestsubjectfrom").validate().form())
                    $("#addentrancetestsubjectfrom").ajaxsubmit({
                        url: "/entrytestsubjectsset/addtestsubject/",
                        datatype: 'json',
                        clearform: false,
                        data: {
                            strjson: json.stringify({
                                test_course_id: idarray.join("&")
                            })
                        },
                        success: function (data) {
                            var json = eval("(" + data + ")");
                            jalert(json.msg, "提示信息");
                            if (json.suc == 1) {
                                $("#entrancetestsubjcetmask").hide();
                                $("#entranceaddtestsubjectset").hide();
                                $("#entrancetestsubjectgrid").trigger("reloadgrid");
                                reloadnum++;
                            }
                        }
                    });
            }
        });
    });