bootstrapValidator 开始日期与结束日期相互验证

 

$("#formAppointment").bootstrapValidator({
        message: '输入值不合法',
        excluded: [":disabled"],
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
             datetimeStart: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请选择开始时间'
                    }
                }
            }, datetimeEnd: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请选择结束时间'
                    },
                    callback: {
                        message: '开始时间必须小于结束时间',
                        callback: function (value, validator, $field) {
                            let other = validator.getFieldElements('datetimeStart').val();//获得另一个的值

                            let start = new Date(other.replace("-", "/").replace("-", "/"));
                            let end = new Date(value.replace("-", "/").replace("-", "/"));

                            if (start <= end) {
                                return true;
                            }
                            return false;
                        }
                    }
                }
            }
            
        }
    });

 

你可能感兴趣的:(Jquery,Bootstrap)