HTML

<input type="text" id="date1" class="layui-input" name="time" autocomplete="off">

JS

        laydate.render({
          elem: '#date1',
          format: "yyyy-MM-dd~yyyy-MM-dd",
          btns: ['clear', 'now'],
          trigger: 'click',
          done: function(value, date, endDate){
              if(value!="" && value.length>0){
                   var today=new Date(value.substring(0,10));
                  var weekday=today.getDay();
                  var monday;
                  var sunday;
                  if (weekday==0) {
                     monday=new Date(1000*60*60*24*(weekday-6) + today.getTime());
                  }  else {
                      monday=new Date(1000*60*60*24*(1-weekday) + today.getTime());
                  }
                  if (weekday==0) {
                     sunday=today;
                  }  else {
                     sunday=new Date(1000*60*60*24*(7-weekday) + today.getTime());
                  }
                  var month = monday.getMonth()+1;
                  if(month<10)
                  {
                      month = "0"+month;
                  }
                  var day1 = monday.getDate();
                  if(day1<10)
                  {
                      day1 = "0"+day1;
                  }
                  var start = ""+monday.getFullYear()+"-"+month+"-"+day1;
                  var month2 = sunday.getMonth()+1;
                  if(month2<10)
                  {
                      month2 = "0"+month2;
                  }
                  var day2 = sunday.getDate();
                  if(day2<10)
                  {
                      day2 = "0" + day2;
                  }
                  var end = ""+sunday.getFullYear()+"-"+month2+"-"+day2;
                  $("#date1").val(start+"~"+end);
              }else{
                   $("#date1").val('');
              }

            }
        });

如若时光萧瑟去丶
111 声望9 粉丝

weakChickenPeng.