当前位置: 编程技术>jquery
JQuery validate日期比较实例
来源: 互联网 发布时间:2014-10-04
本文导语: 例子,JQuery validate应用实例。 代码示例: $(function() { jQuery.validator.methods.compareDate = function(value, element, param) { //var startDate = jQuery(param).val() + ":00";补全yyyy-MM-dd HH:mm:ss格式 //value = value + ":00...
例子,JQuery validate应用实例。
代码示例:
$(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.
});
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.
});
2.
代码示例:
$(function(){
$.validator.addMethod(
"compareDate",
function (value, element) {
var startDate = $('#orgCreateDate').val();
return new Date(Date.parse(startDate.replace("-", "/")))