jQuery Datepicker过期日期

jQuery Datepicker Expiration date

本文关键字:日期 过期 Datepicker jQuery      更新时间:2023-09-26

我使用jQuery UI的Datepicker插件。当用户登录时,一旦过期日期过期,我需要显示一条错误消息。我试着在下面添加if语句,但它不起作用。什么好主意吗?

    $("#expDate").datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: 0
    });
   if (Date.parse(expDate) < jQuery.now()) {
      $("#expDate").addClass("error");// . for class  expDate
  }

也许您忘记添加jquery选择器到expDate?

尝试使用:

if (Date.parse($('#expDate')) < jQuery.now())

使用jQuery进行过期日期验证

Gemfile:

gem 'bootstrap-datepicker-rails'

application.js

//= require datapicker/bootstrap-datepicker.js

application.css.scss

*= require datapicker/datepicker3.css

application.js:

    $(document).ready(function(){
      $('.datepicker').datepicker({
        format: "yy-mm-dd",
        startDate: new Date('2019-1-1'), 
        endDate: new Date('2025-12-31')
      });
    };
});