<script type="text/javascript">
var now = new Date(), cur_day;
$(function () {
showData()
//前一天
$('#prv_day').click(function () {
now = now.dateAdd('d', -1);
showData();
});
//后一天
$('#next_day').click(function () {
now = now.dateAdd('d', 1);
showData();
});
//今天
$('#today').click(function () {
now = new Date();
showData();
});
//昨天
$('#yesterday').click(function () {
now = new Date(); now = now.dateAdd('d', -1);
showData();
});
//前天
$('#before_yesterday').click(function () {
now = new Date();
now = now.dateAdd('d', -2);
showData();
});
})
function showData() {
var time = now.getFullYear() + '-' + now.getCurMonth() + '-' + now.getCurDay();
$('#cur_day').html(time); //显示当前日期
if (now > (new Date().dateAdd('d', -1))) {
$('#next_day').hide(); //如果时间为今天则隐藏后一天按钮
}
else {
$('#next_day').show();
}
/************这里根据时间获取相关数据***********/
}
Date.prototype.getCurMonth = function () {
var m = this.getMonth() + 1
if (m > 9)
return m;
else
return '0' + m;
}
Date.prototype.getCurDay = function () {
var d = this.getDate();
if (d > 9)
return d;
else
return '0' + d;
}
Date.prototype.dateAdd = function (interval, number) {
var d = this;
var k = { 'y': 'FullYear', 'q': 'Month', 'm': 'Month', 'w': 'Date', 'd': 'Date', 'h': 'Hours', 'n': 'Minutes', 's': 'Seconds', 'ms': 'MilliSeconds' };
var n = { 'q': 3, 'w': 7 };
eval('d.set' + k[interval] + '(d.get' + k[interval] + '()+' + ((n[interval] || 1) * number) + ')');
return d;
}
</script>
声明:OSCHINA 博客文章版权属于作者caishbian,受法律保护。转载请注明出处:www.meibaizn.com。
转载于:https://my.oschina.net/u/564907/blog/146630