【问题标题】:Date comparison is not working in jQuery listener日期比较在 jQuery 侦听器中不起作用
【发布时间】: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');
  }
})

【问题讨论】:

标签: javascript jquery date-comparison


【解决方案1】:

尝试在比较之前将您的日期变量转换为对象。

例如:

var date = document.getElementById('<%= txtRegisteredDate.ClientID%>').value;
var todaydates = new Date();

if((new Date(date) > todaydates))
{
   alert('date is greater than today date');
}

【讨论】:

  • 如果这解决了您的问题,请接受作为答案:)
猜你喜欢
  • 2011-11-24
  • 1970-01-01
  • 2018-05-18
  • 2018-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多