帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 简单的日历
简单的日历
浏览:569次
-
评论:0次
-
发布时间:2020-05-27
Html
Css
Js
<
>
日
一
二
三
四
五
六
#cldFrame { position:relative; width:600px; margin:50px auto; } #cldBody { margin:10px; position:absolute; width:600px; } #top { font-family:'微软雅黑'; position:relative; height:40px; text-align:center; line-height:40px; } #topDate { font-size:17px; font-weight:700; } .curDate { color:red; font-weight:bold; } table { background-color:#f7f7f7; } #week td { font-size:9px; color:#797979; } td { height:30px; width:30px; text-align:center; font-family:'微软雅黑'; font-size:15px; } #left,#right { position:absolute; width:40px; height:40px; } #left { left:0px; font-size:20px; color:#6b6b50; } #right { right:0px; font-size:20px; color:#6b6b50; } #left:hover,#right:hover { background-color:rgba(71,71,71,0.2); } /* border:solid #3461e4 0.5px; border-radius:50px; */
/*判断某年是否是闰年*/ function isLeap(year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return true; } else { return false; } } var monthDay = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /*判断某年某月某日是星期几,默认日为1号*/ function whatDay(year, month, day = 1) { var sum = 0; sum += (year - 1) * 365 + Math.floor((year - 1) / 4) - Math.floor((year - 1) / 100) + Math.floor((year - 1) / 400) + day; for (var i = 0; i < month - 1; i++) { sum += monthDay[i]; } if (month > 2) { if (isLeap(year)) { sum += 29; } else { sum += 28; } } return sum % 7; //余数为0代表那天是周日,为1代表是周一,以此类推 } /*显示日历*/ function showCld(year, month, firstDay) { var i; var tagClass = ""; var nowDate = new Date(); var days; //从数组里取出该月的天数 if (month == 2) { if (isLeap(year)) { days = 29; } else { days = 28; } } else { days = monthDay[month - 1]; } /*当前显示月份添加至顶部*/ var topdateHtml = year + "年" + month + "月"; var topDate = document.getElementById('topDate'); topDate.innerHTML = topdateHtml; /*添加日期部分*/ var tbodyHtml = '
'; for (i = 0; i < firstDay; i++) { //对1号前空白格的填充 tbodyHtml += "
"; } var changLine = firstDay; for (i = 1; i <= days; i++) { //每一个日期的填充 if (year == nowDate.getFullYear() && month == nowDate.getMonth() + 1 && i == nowDate.getDate()) { tagClass = "curDate"; //当前日期对应格子 } else { tagClass = "isDate"; //普通日期对应格子,设置class便于与空白格子区分开来 } var setId = year + '' + month + '' + i; console.log(setId); tbodyHtml += "
" + i + "
"; //tbodyHtml += "
"+i+"
"; changLine = (changLine + 1) % 7; if (changLine == 0 && i != days) { //是否换行填充的判断 tbodyHtml += "
"; } } if (changLine != 0) { //添加结束,对该行剩余位置的空白填充 for (i = changLine; i < 7; i++) { tbodyHtml += "
"; } } //实际上不需要填充后方,但强迫症必须整整齐齐! tbodyHtml += "
"; var tbody = document.getElementById('tbody'); tbody.innerHTML = tbodyHtml; } var curDate = new Date(); var curYear = curDate.getFullYear(); var curMonth = curDate.getMonth() + 1; showCld(curYear, curMonth, whatDay(curYear, curMonth)); function nextMonth() { var topStr = document.getElementById("topDate").innerHTML; var pattern = /\d+/g; var listTemp = topStr.match(pattern); var year = Number(listTemp[0]); var month = Number(listTemp[1]); var nextMonth = month + 1; if (nextMonth > 12) { nextMonth = 1; year++; } document.getElementById('topDate').innerHTML = ''; showCld(year, nextMonth, whatDay(year, nextMonth)); } function preMonth() { var topStr = document.getElementById("topDate").innerHTML; var pattern = /\d+/g; var listTemp = topStr.match(pattern); var year = Number(listTemp[0]); var month = Number(listTemp[1]); var preMonth = month - 1; if (preMonth < 1) { preMonth = 12; year--; } document.getElementById('topDate').innerHTML = ''; showCld(year, preMonth, whatDay(year, preMonth)); } document.getElementById('right').onclick = function() { nextMonth(); } document.getElementById('left').onclick = function() { preMonth(); }
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>简单的日历-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:简单的js日历
简单的日历插件(html+css+js)效果
简单的json查询封装 减少工作量
极其简单的导航菜单
讨论这个常用代码(0)
回答他人问题或分享心得会奖励牛币
〒_〒 居然一个评论都没有……
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
569
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值