欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-07-05 11:19:11
开始时间 :
结束时间 :<......
    <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;
        }



    });

 

本文地址:https://blog.csdn.net/qq_39313596/article/details/107481444

相关标签: layui