$(function() {
jQuery.validator.methods.compareDate = function(value, element, param) {
//var startDate = jQuery(param).val() + ":00";补全yyyy-MM-dd HH:mm:ss格式
//value = value + ":00";
var startDate = jQuery(param).val();
var date1 = new Date(Date.parse(startDate.replace("-", "/")));
var date2 = new Date(Date.parse(value.replace("-", "/")));
return date1 < date2;
};
jQuery("#__edit-form").validate({
focusInvalid:false,
rules:{
"orgCreateDate":{
required: false
},
"orgCancelDate": {
required: false,
compareDate: "#orgCreateDate"
}
},
messages:{
"orgCreateDate":{
required: "成立日不能为空!"
},
"orgCancelDate":{
required: "注销日期不能为空!",
compareDate: "注销日期必须大于成立日期!"
}
}
}); */ www.jb200.com
});
2.
$(function(){
$.validator.addMethod(
"compareDate",
function (value, element) {
var startDate = $('#orgCreateDate').val();
return new Date(Date.parse(startDate.replace("-", "/"))) <= new Date(Date.parse(value.replace("-", "/")));
},
"结束日期必须大于开始日期"
);
});
<input type="text" id="orgCancelDate" name="orgCancelDate" size="10"
readonly="true" validate="{required:false,compareDate:true,maxlength:12}" value="<fmt:formatDate value="${org.orgCancelDate}" pattern="yyyy/MM/dd"/>" />