【发布时间】:2018-12-11 14:41:57
【问题描述】:
警报显示每个更改事件,但 if 条件不起作用。如何解决?
这是我的代码。
$("input").change(function() {
var date = document.getElementById('<%= txtRegisteredDate.ClientID%>').value;
var todaydates = new Date().format('dd/MM/yyyy');
if (date > todaydates) {
alert('date is greater than today date');
}
})
【问题讨论】:
-
日期中没有
format函数 -
即使
.format有效。为什么要以dd/MM/yyyy格式比较字符串?如果你想比较字符串,你会使用yyyy-mm-dd。但是你可以直接比较Date对象:new Date() < someOtherDate。 -
你可能想看看这个问题stackoverflow.com/questions/23641525/…
标签: javascript jquery date-comparison