代码之家  ›  专栏  ›  技术社区  ›  story ks

daterangepicker如何获取值并按1day在输入文本上显示日期

  •  0
  • story ks  · 技术社区  · 7 年前

    我想选择一个日期并将其插入表中。

    例如,我选择一个日期:

    enter image description here

    enter image description here

    以下是Javascript代码:

    $('input[name="allotment"]').on('apply.daterangepicker', function(ev, picker) {
      var allomentDate = picker.endDate.format('DD') - picker.startDate.format('DD');
      console.log(allomentDate);
      console.log(picker);
      /* for (i=1;i<=allomentDate;i++){
          var dd = start.format('DD').toString();
          console.log(dd);
          var dateAllot = dd+1;
          console.log(dateAllot);
          var addRow = "<tr><td><input type='text' name='allomentDate[dateAllot]' readonly value=''></td>" + "<tr><td>";
      }*/
    });
    

    不过,这才刚刚开始。现在,我仍然无法得到startdate和enddate的值。

    1 回复  |  直到 7 年前
        1
  •  0
  •   story ks    7 年前
     $('input[name="allotment"]').daterangepicker({
                    "drops": "down",
                    "opens": "center",
                }, function (start, end, label) {
                    console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
                    var dd = parseInt(end.format('DD')) - parseInt(start.format('DD'));
                    var startDate = new Date(start.format('YYYY-MM-DD'));
                    var endDate = new Date(end.format('YYYY-MM-DD'));
                    //console.log(startDate.getDate());
                    //console.log(endDate.getDate());
                    //console.log(allot);
                    for (i=1;i<=dd;i++){
                        var allot = startDate.getDate()+1;
                        console.log(allot);
                        var addRow = "<tr><td><input type='text' name='allomentDate[i]' readonly value='startDate'></td>" +
                            "<tr><td>";
                    }
                });
    

    套开始.格式('YYYY-MM-DD')到日期和使用获取。日期+ 1