js日付をクリックして、現在の日付の前または後の毎日を選択します.
5840 ワード
function change(type) {
var nowTimestamp = Date.parse(new Date());
var year = document.getElementById('year').innerHTML;
var month = document.getElementById('month').innerHTML;
var day = document.getElementById('day').innerHTML;
var timestamp = Date.parse(new Date(year + '-' + month + '-' + day));
if (type == 'prev') {
var changeTimestamp = timestamp - 24 * 60 * 60 * 1000;
$('#right').addClass('bagright')
} else {
var changeTimestamp = timestamp + 24 * 60 * 60 * 1000;
if (changeTimestamp > nowTimestamp) {
$('#right').removeClass('bagright')
return;
} else {
$('#right').addClass('bagright')
}
}
var date = new Date(changeTimestamp);
var changeYear = date.getFullYear();
var changeMonth = setDate(date.getMonth() + 1);
var changeDay = setDate(date.getDate());
document.getElementById('year').innerHTML = changeYear;
document.getElementById('month').innerHTML = changeMonth;
document.getElementById('day').innerHTML = changeDay;
changeDate = changeYear + '-' + changeMonth + '-' + changeDay;
timeStr = changeYear + changeMonth + changeDay;
}
//1-9 0
function setDate(date) {
if (date < 10) {
date = '0' + date;
}
return date;
}