jQuery,月历,左右点击事件实现月份的改变
html页面:
<div class="recordbriefing-title-top-body">
<span class="record-left"></span>
<p class="record-Ptime"></p>
<span class="record-right"></span>
</div>
css样式:
.record-left{
content: "";
width: 0;
height: 0;
float: left;
border-top: 10px solid transparent;
border-right: 10px solid red;
border-bottom: 10px solid transparent;
margin-top:5px;
}
.record-right{
content: "";
width: 0;
height: 0;
float: right;
border-top: 10px solid transparent;
border-left: 10px solid red;
border-bottom: 10px solid transparent;
margin-top:5px;
margin-right: 25px;
}
.record-Ptime{
display:inline-block;
width: 80%;
font-size: 16px;
color: #000;
text-align: center;
line-height: 31px;
}
js部分:
$(function() {
var rsValue='';
var todayData=new Date();
var year= todayData.getFullYear();
var month= todayData.getMonth();//月份从0开始
// console.log(typeof month);
var day=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var todayDay;
for(var i=0;i<day.length;i++){
if(i==month){
todayDay=day[i];
}
if((year%4)==0){
if((month+1)==2){
todayDay=29;
}
}
}
if(month>9){
rsValue=year+'.'+(month+1)+'.01~'+year+'.'+(month+1)+'.'+todayDay;
}else{
rsValue=year+'.0'+(month+1)+'.01~'+year+'.0'+(month+1)+'.'+todayDay;
}
// console.log(rsValue);
// 得到的拼接时间显示在页面上
$(".record-Ptime").empty();
$('.record-Ptime').append(rsValue);
changeTime();
// 上个月 左边改变时间事件
var j=1;
$(".record-left").on("click", function(){
j--;
// 判断月份是否>0,是13时就年份加1
if((month+j)<=0){
year-=1;
month=11;
j=1;
}
for(var i=0;i<day.length;i++){
if(i==(month+j-1)){
todayDay=day[i];
}
if((year%4)==0){
if((month+j)==2){
todayDay=29;
}
}
}
if((month+j)>9){
rsValue=year+'.'+(month+j)+'.01~'+year+'.'+(month+j)+'.'+todayDay;
}else{
rsValue=year+'.0'+(month+j)+'.01~'+year+'.0'+(month+j)+'.'+todayDay;
}
// 得到的拼接时间显示在页面上
$(".record-Ptime").empty();
$('.record-Ptime').append(rsValue);
changeTime();
});
// 下个月 右边改变时间事件
$(".record-right").on("click", function(){
j++;
// 判断月份是否>12,是13时就年份加1
if((month+j)>12){
year+=1;
month=0;
j=1;
}
for(var i=0;i<day.length;i++){
if(i==(month+j-1)){
todayDay=day[i];
}
if((year%4)==0){
if((month+j)==2){
todayDay=29;
}
}
}
if((month+j)>9){
rsValue=year+'.'+(month+j)+'.01~'+year+'.'+(month+j)+'.'+todayDay;
}else{
rsValue=year+'.0'+(month+j)+'.01~'+year+'.0'+(month+j)+'.'+todayDay;
}
// 得到的拼接时间显示在页面上
$(".record-Ptime").empty();
$('.record-Ptime').append(rsValue);
changeTime();
});
});
最新文章
- XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg
- NOIP 考前 高斯消元练习
- C#之延迟加载
- 【Ext.Net学习笔记】05:Ext.Net GridPanel的用法(包含Filter、Sorter、Grouping、汇总(Summary)的用法)
- 让Laravel5支持memcache的方法
- RH033读书笔记(9)-Lab 10 Understanding the Configuration Tools
- Hadoop集群搭建的密钥配置SSH实现机制
- salesforce 零基础学习(六十八)http callout test class写法
- if中可以使用那些作为判断条件呢?
- CART决策树和随机森林
- 苹果中国全系降价:iphone最高降500元,用户可退差价
- 软件工程启程篇章:结对编程和进阶四则运算(197 &; 199)
- Flink - Scheduler
- iOS UI进阶-6.0 手势
- Cross-site request forgery 跨站请求伪造
- Java&#160;java&#160;jdk在Linux下安装与环境变量的配置
- Scramble String leetcode java
- Linux抓包工具
- Oracle 学习之exists
- git忽略操作
热门文章
- Halcon17无法加载";hdevenginecpp";:找不到指定的模块
- PAT——乙级1006:换个格式输出整数&;乙级1021:个位数统计&;乙级1031:查验身份证
- MyBatis实例教程--开发环境搭建
- 【Python】python中的__dict__,__getattr__,__setattr__
- Java语言课程设计
- 【Linux】Linux修改openfile和max user processes?
- 玩转VFS(二)
- JSP动作标识
- log4net将日志写入ElasticSearch
- hdu 1695 GCD (欧拉函数+容斥原理)