【发布时间】:2014-03-20 00:06:16
【问题描述】:
在日期选择器中,我想限制输入以防止过去的日期。我使用了下面的 JavaScript,但在某些情况下它会失败。
function isPastDate(value) {
var now = new Date;
var target = new Date(value);
if (target.getFullYear() < now.getFullYear()) {
return true;
} else if (target.getMonth() < now.getMonth()) {
return true;
} else if (target.getDate() < now.getDate()) {
return true;
}
return false;
}
有人可以帮我吗?
【问题讨论】:
-
在哪些情况下会失败?
-
你把一件简单的事情复杂化了
console.log(now > target) -
有人从这里复制了答案:stackoverflow.com/questions/17344318/…??
-
@epascarello 是的,我关注了那个但失败了。
-
失败了怎么办?解释它是如何失败的......
标签: javascript jquery