参考之前写的,jeDate日期控件的使用以及选中后点确定按钮关闭功能
https://www.jianshu.com/p/393d9e992144。
但是现在要在日历上增加一个小功能,可提供选择日期不超过当前日期,比如今天是8.5号,超出5号以后的日期都默认不可选。
<!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>
效果如下
原文作者:祈澈姑娘 技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,文艺与代码齐飞,魅力与智慧共存的程序媛一枚,欢迎关注【编程微刊】公众号,回复【领取资源】,500G编程学习资源干货免费送。