layui的时间框开始时间、结束时间限制

    createTimeInit:function (start,end){
        var time = new Date();//当前时间
        var startTime = layui.laydate.render({
                elem:start,
                min:hs.formatDate(time),
                done: function (value,date,endDate) {
                    //如果修改的开始时间为空,初始化控件
                    if(value){
                        endTime.config.min = {
                            year: time.getFullYear(),
                            month: time.getMonth(),
                            date:time.getDate()
                        }
                    }else {
                        endTime.config.min = {
                            year: date.year,
                            month: date.month-1,
                            date:date.date
                        }
                    }
                }
            });

        var endTime = layui.laydate.render({
            elem:end,
            min:hs.formatDate(time),
            done:function (value,date,endDate) {
                if(value){
                    startTime.config.max = {
                        year: time.getFullYear()+10,
                        month: time.getMonth(),
                        date:time.getDate()
                    }
                }else {
                    if(new Date(value).getTime() < new Date($(start).val()).getTime() && hs.isNotEmpty($(start).val())){
                        $(end).val("");
                        layui.layer.msg("不在有效日期或时间范围内");
                    }else {
                        startTime.config.max = {
                            year: date.year,
                            month: date.month-1,
                            date:date.date
                        }
                    }
                }
            }
        });
    },

 

你可能感兴趣的:(js)