现在的位置: 首页 > 综合 > 正文

jQuery Validator插件增加日期比较

2018年01月29日 ⁄ 综合 ⁄ 共 636字 ⁄ 字号 评论关闭

 

$(document).ready(function() {
    $("#< %= btnSubmit.ClientID %>").click(function() {
        $("#aspnetForm").validate({
            rules: {
                ctl00$ContentPlaceHolder1$ucProjInfo1$ucDatePicker2$txtDatePicker: {
                    required: true,
                    date: true,
                    //日期比较验证方法
                    endDate: true
                }
            }
        });
    });
    //自定义验证方法
    jQuery.validator.addMethod("endDate",
    function(value, element) {
        var startDate = $('#start_date').val();
        return new Date(Date.parse(startDate.replace("-", "/"))) < = new Date(Date.parse(value.replace("-", "/")));
    },
    "结束日期必须大于开始日期!");
});

抱歉!评论已关闭.