jquery validate日期比较方法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script type="text/javascript" src="jquery-1.4.2.js"></script> <script type="text/javascript" src="jquery.validate.js"></script> <SCRIPT LANGUAGE="JavaScript"> <!-- jQuery(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("#form1").validate({ focusInvalid:false, rules:{ "timeStart":{ required: true }, "timeEnd": { required: true, compareDate: "#timeStart" } }, messages:{ "timeStart":{ required: "开始时间不能为空" }, "timeEnd":{ required: "结束时间不能为空", compareDate: "结束日期必须大于开始日期!" } } }); }); //--> </SCRIPT> </HEAD> <BODY> <form id="form1" name="form1" method="post" action="demo.html"> <p>timeStart: <input name="timeStart" type="text" id="timeStart" value="2011-02-17 10:00:00"> yyyy-MM-dd HH:mm:ss </p> <p>timeEnd: <input name="timeEnd" type="text" id="timeEnd" value="2011-02-17 9:00:00"> yyyy-MM-dd HH:mm:ss </p> <p> <input type="submit" name="Submit" value="提交"> </p> </form> </BODY> </HTML>
相关推荐
tztzyzyz 2020-07-20
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
83510998 2020-07-18
81463166 2020-07-17