您的位置:首页 > 产品设计 > UI/UE

EasyUi 日期赋默认值 并且限制选择的日期小于当前日期

2018-01-04 13:42 357 查看
HTML代码

<input name="" id="planRunDt" class="easyui-datebox" data-options="editable:false">  

JS代码:

$('#planRunDt').datebox('setValue', getCurentDateStr());  //赋默认值为当前日期

    $('#planRunDt').datebox('calendar').calendar({  //设置日期小于当前日期

        validator : function(date){  

            var now = new Date();  

            var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());  

            return date <= d1;  

        }  

});  

$('#start').datebox({//当选择开始日期时,给结束日期增加验证大于开始日期

    onSelect: function(date){

        $('#end').datebox('calendar').calendar({  

           validator : function(date1){  

               var d1 = new Date(date.getFullYear(),date.getMonth(),date.getDate());  

               return date1 >= d1;  

           }  

    });  

    }

});  

function getCurentDateStr()  {   

    var now = new Date();  

    var year = now.getFullYear();       //年  

    var month = now.getMonth() + 1;     //月  

    var day = now.getDate();            //日  

    var clock = year + "-";  

    if(month < 10) clock += "0";         

    clock += month + "-";  

    if(day < 10) clock += "0";   

    clock += day;  

    return clock;   

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Easyui