设置easyUI的日历选择范围

在使用easyUI的日历插件时,不加以设置的话日历上的每一天都可以选择,最近工作需要规定当天以前的日期是不能被选择~其实不难哦~我向来比较爽快,没那么多文字,直接上代码,不懂的可以问我,估计大家一看就懂,嘻嘻(^__^) 嘻嘻……

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置日历选择范围</title>
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.2/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.2/themes/icon.css"/>
    <style type="text/css">
        .calendarBox{
            width: 500px;
            height: 500px;
            background-color: #ccc;
            margin: auto;
        }
    </style>
</head>
<body>
    <div class="calendarBox">
        <div id="calendar"></div>
        <input id="dateBox" class="easyui-datebox" name="dateBox" required>
    </div>
    <script type="text/javascript" src="jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    $("#calendar").calendar({
        validator: function(date){
            var now = new Date();
            var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
            return d1<=date;
        },
        current:new Date(),   
        onSelect: function(date){
            //alert(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
            if((date.getMonth()+1)<10){
                mTDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-"+date.getDate();
                alert(mTDate);
            }else{
                mTDate = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
                alert(mTDate);
            }
        }
    });
    //easyui-datebox
    $("#dateBox").datebox().datebox('calendar').calendar({
        validator: function(date){
            var now = new Date();
            var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
            return d1<=date;
        }
    });
    $("#dateBox").datebox({
        onSelect: function(date){
            // alert(now.getFullYear(), now.getMonth(), now.getDate());
            alert(date);
        }
    }); 
    </script>
</body>
</html>

效果如下:
这里写图片描述

当天之前的日期都是不能被选中的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值