JS 点击实现上一天下一天
来源:互联网 发布:马哲外设淘宝店 编辑:程序博客网 时间:2024/06/02 09:35
我用的laydate 的插件,#prev_day 是一个上一页按钮 ,#LAY_demorange_s 是时间插件的input 他的val就是日期
思路,写好Format 方法 转换成日期格式。使用getDate 获取当天日期。在使用setDate把日期放进去。在Format 方法 完成转换,
不会用给我留言,别去别处找了,都是坑,我这个保准好用。
上一天:
$("#prev_day").on("click",function(){
Date.prototype.Format = function (fmt) { //author: meizzvar o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
var dt = new Date($("#LAY_demorange_s").val());
$("#LAY_demorange_s").val(new Date(dt.setDate(dt.getDate()+1)).Format("yyyy-MM-dd"));
});
下一天:
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
var dt = new Date($("#LAY_demorange_s").val());
$("#LAY_demorange_s").val(new Date(dt.setDate(dt.getDate()-1)).Format("yyyy-MM-dd"));
})
阅读全文
2 0
- JS 点击实现上一天下一天
- 点击上一天下一天判断
- 取得下一天和上一天的日期
- js实现获取上一个月的一天,和最后一天
- (工作笔记)报表的展示,保留2位小数和实现上一天下一天查询
- js获取指定日期的下一天
- js计算输入日期的前一天,后一天(上一日,下一日)。兼容safari
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 一天
- 多目标优化系列(七)SPEA2
- 2018.8.19总结3-Zjr506的捕猫计划
- JavaWeb 简单的 struts2
- JZOJ1776. 经济编码(2017.8B组)
- Kanzi入门学习教程
- JS 点击实现上一天下一天
- springmvc拦截器实现权限管理
- 289. Game of Life
- 【转】linux下杀死进程(kill)的N种方法
- SVN的主干(trunk)、分支(branch)和标记(tag)
- presto对orc文件的读取
- 40. Combination Sum II
- GET方法传参解决中文乱码
- [软件测试]