代码之家  ›  专栏  ›  技术社区  ›  Codecraker

Datepicker只能使用两位数的输入

  •  -1
  • Codecraker  · 技术社区  · 6 年前

    在我的代码中,我有一个引导日期选择器,但当我将日期设置为09/24/2018时,它不工作,但是,9/24/2018正在工作。 每当日期数字是个位数时,我想加一个0。

    在Jquery中

              var onlyThisDates = ["09/25/2018", "09/26/2018", "09/29/2018", "09/27/2018", "09/20/2018", "09/21/2018", "09/22/2018", "10/01/2018", "10/03/2018", "10/05/2018", "10/11/2018", "10/15/2018", "10/17/2018"];
    
              console.log(onlyThisDates);
    
              $('#doctortime').datepicker({
                  format: "mm/dd/yyyy",
                  autoclose: true,
                  beforeShowDay: function (date) {
                      var dt_ddmmyyyy =(date.getMonth() + 1)  + '/' + date.getDate() + '/' + date.getFullYear();
                      return (onlyThisDates.indexOf(dt_ddmmyyyy) != -1);
                  }
              });
    

    在HTML中

    <input id="doctortime" class="form-control" placeholder="Doctor Date" name="dates" data-date-format="mm/dd/yyyy" /> 
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Ahmed Yousif    6 年前

    你想要这样吗?

    https://jsfiddle.net/9vqs2e1L/8/

        var onlyThisDates = ["09/20/2018", "09/26/2018", "09/29/2018", "09/27/2018", "09/20/2018", "09/21/2018", "09/22/2018", "10/01/2018", "10/03/2018", "10/05/2018", "10/11/2018", "10/15/2018", "10/17/2018"];         
    
          $('#doctortime').datepicker({
              format: "mm/dd/yyyy",
              autoclose: true,
               beforeShowDay: function (date) {                              
                var dt_ddmmyyyy = ('0' + (date.getMonth() + 1)).slice(-2)  + '/' + ('0' + date.getDate()).slice(-2) + '/' + date.getFullYear();                                     
                return (onlyThisDates.indexOf(dt_ddmmyyyy) != -1);                  
              }
          });