前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jeDate可提供选择日期不超过当前日期

jeDate可提供选择日期不超过当前日期

作者头像
王小婷
发布2019-08-07 15:30:38
1.3K0
发布2019-08-07 15:30:38
举报
文章被收录于专栏:编程微刊

参考之前写的,jeDate日期控件的使用以及选中后点确定按钮关闭功能

https://cloud.tencent.com/developer/article/1411281

但是现在要在日历上增加一个小功能,可提供选择日期不超过当前日期,比如今天是8.5号,超出5号以后的日期都默认不可选。

代码语言:javascript
复制
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input placeholder="开始时间" id="startTime"  type="text"> 
        <input  placeholder="结束时间" id="stopTime"  type="text">
    </body>
    <link type="text/css" rel="stylesheet" href="jeDate-gh-pages/test/jeDate-test.css">
    <link type="text/css" rel="stylesheet" href="jeDate-gh-pages/skin/jedate.css">
    <script type="text/javascript" src="jeDate-gh-pages/src/jedate.js"></script>
    
    <script>
        Date.prototype.format = function(format) {
            var o = {
                "M+" : this.getMonth() + 1, // month
                "d+" : this.getDate(), // day
                "h+" : this.getHours(), // hour
                "m+" : this.getMinutes(), // minute
                "s+" : this.getSeconds(), // second
                "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
                "S" : this.getMilliseconds()
            // millisecond
            };
            if (/(y+)/.test(format)) {
                format = format.replace(RegExp.$1, (this.getFullYear() + "")
                        .substr(4 - RegExp.$1.length));
            }
            for ( var k in o) {
                if (new RegExp("(" + k + ")").test(format)) {
                    format = format.replace(RegExp.$1,
                            RegExp.$1.length == 1 ? o[k] : ("00" + o[k])
                                    .substr(("" + o[k]).length));
                }
            }
            return format;
        };
        var nowt = new Date().format("yyyy-MM-dd");
        //选中后点确定按钮才关闭
        jeDate("#startTime", {
            onClose : true,
            theme : {
                bgcolor : "#00A1CB",
                color : "#ffffff",
                pnColor : "#00CCFF"
            },
            format : 'YYYY-MM-DD',
            maxDate : nowt
        });
        jeDate("#stopTime", {
            onClose : true,
            theme : {
                bgcolor : "#00A1CB",
                color : "#ffffff",
                pnColor : "#00CCFF"
            },
            format : 'YYYY-MM-DD',
            maxDate : nowt
        });
    </script>
</html>

效果如下

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.08.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档