javascript - 日期比较在 jQuery 侦听器中不起作用
问题描述
警报显示每个更改事件,但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');
}
})
解决方案
尝试在比较之前将您的日期变量转换为对象。
例如:
var date = document.getElementById('<%= txtRegisteredDate.ClientID%>').value;
var todaydates = new Date();
if((new Date(date) > todaydates))
{
alert('date is greater than today date');
}
推荐阅读
- d3.js - Highcharts - 具有 y 轴值的时间序列图表需要与文本标签分组
- android - MotionLayout中touchAnchorSide的作用是什么?
- angular - Ionic:错误:NgModule 'AppModule' 的提供程序无效
- postgresql - postgresql 请求数据库sql
- python - 从多个子图之一共享轴
- maven - 在 JitPack 和其他存储库之间保持 jar 版本号同步
- c++ - 实现 k 最短路径问题
- c - load_file 正在跳过空字节
- python - Function to extract company register number from text string using Regex
- javascript - 无法使用 react 和 redux 在待办事项列表中添加待办事项。我究竟做错了什么?