easyUI的datebox,开始/结束日期不得大于当前日期,开始日期不得大于结束日期

 

 type="text/javascript">
    
    //得到当前日期
        formatterDate function(date) {
        var day date.getDate() 9 date.getDate() "0" date.getDate();
        var month (date.getMonth() 19 (date.getMonth() 1"0"
        (date.getMonth() 1);
        return date.getFullYear() '-' month '-' day;
        };
        
        window.onload function() {
        $('#startTime').datebox('setValue'formatterDate(new Date()));
        $('#endTime').datebox('setValue'formatterDate(new Date()));
        
        /* alert($('#startTime').val()); */
        /* 日期开始、结束输入框赋值 */
            var startTime $('#startTime').datebox('getValue');   
            var endTime $('#endTime').datebox('getValue');
            var nowTime formatterDate(new Date())
            /* alert(nowTime); */
        };
        /* 被调用方法,将日期转换为秒数,进行判断 */
        function isValidTime(startTime,endTime,nowTime){
            var nowstrs nowTime.split("-");
            var nowyear nowstrs[0];
            var nowmonth nowstrs[1];
            var nowday nowstrs[2];
            var nowDate new Date(nowyear,nowmonth,nowday)
            var nowtime nowDate.getTime();
        
            var startstrs startTime.split("-");
            var startyear startstrs[0];
            var startmonth startstrs[1];
            var startday startstrs[2];
            var startDate new Date(startyear,startmonth,startday)
            var starttime startDate.getTime();
             
            var endstrs endTime.split("-");
            var endyear endstrs[0];
            var endmonth endstrs[1];
            var endday endstrs[2];
            var endDate new Date(endyear,endmonth,endday)
            var endtime endDate.getTime();
               if(starttime>endtime){
                    alert("开始日期不能大于结束日期");
                    return false;     
               }else if(starttime>nowtime){
                       alert("开始日期不能大于当前日期");
                       return false;
               }else if(endtime>nowtime){
                       alert("结束日期不能大于当前日期");
                       return false;
               }else{    
                   return true;
               }
            };    
        
        $(function(){
            $('#grid').datagrid({
            iconCls'icon-forward',
            fit:true,
            border:false,
            rownumbers:true,
            singleSelect:true,
            striped:true,
            pageList:[10,20,30],
            paginationtrue,
            
            url:"${pageContext.request.contextPath}/pageShopClerk.action"
            idField:'id',
            columnscolumns,
            
        });
        
        $('#goods').click(function(){
            $('#goodsWindow').window("open");
        });    
        $('#goodsType').click(function(){
            $('#goodsTypeWindow').window("open");
        });    
        $('#Reset').click(function(){
            $('#ff').form("clear");
            $('#startTime').datebox('setValue'formatterDate(new Date()));
            $('#endTime').datebox('setValue'formatterDate(new Date()));
            $("#priceStr").textbox("setValue","0");
            $("#priceEnd").textbox("setValue","99999");
            
        });    
        /* 通过点击按钮,调用方法,对日期框进行判断 */
        $('#search').click(function(){
            alert(123);    
            var StartDate $('#startTime').datebox('getValue')
            var EndDate =  $("#endTime").datebox('getValue')
            var nowTime formatterDate(new Date())
            /* alert(StartDate); */
            if(!isValidTime(StartDate,EndDate,nowTime)){
                $('#startTime').datebox('setValue'formatterDate(new Date()));
                $('#endTime').datebox('setValue'formatterDate(new Date()));
                return  false
            }
            else{return true;}
        });    
        
    });

你可能感兴趣的:(easyUI的datebox,开始/结束日期不得大于当前日期,开始日期不得大于结束日期)