layui 日期框开始日期和结束日期不能超过当前时间 并且开始时间不能超结束时间

    
开始时间 :
结束时间 :

    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;
        }



    });

 

你可能感兴趣的:(layui)