【发布时间】:2016-07-15 09:50:30
【问题描述】:
我的表单中有一个输入日期字段。在我的日期字段中 如果输入日期大于我之前定义的任何日期,我需要提醒错误 这是我的代码:
$(document).ready(function () {
var date = new Date(2016,2,1); //the defined date is 1 March 2016
var day = date.getDate();
var month = date.getMonth();
month = month + 1;
if(day < 10){
day = '0' + day;
}
if(month < 10){
month='0'+month;
}
someday = day + '/' + month + '/' + date.getFullYear();
$("#q1 input").blur(function(){ //#q1 is the ID for the input field.
if($('#q1 input').val() > someday){
alert('the input is bigger than the defined');
}else{
alert('the defined is bigger than the input ');
}
});
});
【问题讨论】:
-
如果
q1是输入字段的id,那么我认为你不需要使用#q1 input你可以直接使用#q1。 -
可以直接比较Date对象:
if (date0 > date1) {/* date0 is after date1 */.
标签: javascript jquery date