我如何使用jquery验证两个日期文本框。我遇到了这段代码。我如何输入文本框参数:
$.validator.addMethod('greaterThan', function(value, element, param) { return ( IsNaN( value ) && IsNaN( $(param).val() ) ) || ( value > $(param).val() ); }, 'Must be greater than {0}.' );
$.validator.addMethod('lesserThan', function(value, element, param) { return ( IsNaN( value ) && IsNaN( $(param).val() ) ) || ( value < $(param).val() ); }, 'Must be lesser than {0}.' );
开始日期必须大于结束日期。
答案 0 :(得分:1)
Grab DateJS
<form>
<input type="text" id="startdate" />
<input type="text" id="enddate" />
</form>
<button id="checkdates">Check Dates</button>
<div id="msg"></div>
<script>
$(function() {
$("#msg").text('');
$("#checkdates").click(function(event) {
var startdate = Date.parse($("#startdate").val());
if (!startdate) { $("#msg").append("Start Date is not a valid date<br/>"); }
var enddate = Date.parse($("#enddate ").val());
if (!enddate) { $("#msg").append("End Date is not a valid date<br/>"); }
if (startdate && enddate) {
if (startdate.compareTo(enddate) <= 0) {
$("#msg").append("Start date must be greater than end date");
}
}
event.preventDefault();
return false;
});
});
</script>