The start date and end date of the layui date box cannot exceed the current time and the start time cannot exceed the end time

    <div class="layui-col-xs2">
        开始时间 :<input type="text" name="start_date" id="start_date" placeholder="开始时间" autocomplete="off"  style="width: 50%;height: 25px">
    </div>
    <div class="layui-col-xs2">
        结束时间 :<input type="text" name="end_date" id="end_date" placeholder="结束时间" autocomplete="off"  style="width: 50%;height: 25px">
    </div>

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
         var start_date =   laydate.render({
            elem: '#start_date'
             ,format:'yyyy-MM-dd'
             ,max : nowFormatDate()
             ,done:function(value,date,startDate){
                 end_date.config.min = {
                     year: date.year,
                     month: date.month - 1,
                     date: date.date,
                     hours: date.hours,
                     minutes: date.minutes,
                     seconds: date.seconds
                 }


             }
        });
        var   end_date = laydate.render({
            elem: '#end_date'
            ,format:'yyyy-MM-dd'
            ,max : nowFormatDate()
            ,done:function(value,date,startDate){
                start_date.config.max = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                }

            }
        });



        function nowFormatDate() {
            var date = new Date(new Date()-1000*60*60*24);
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }

            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = date.getFullYear() + seperator1 + month
                + seperator1 + strDate
            return currentdate;
        }



    });

 

Guess you like

Origin blog.csdn.net/qq_39313596/article/details/107481444