0
已經編寫了一個代碼,用於切換幾個月和幾年,就像您在Windows時鐘中看到的,當您在右下角點擊它時。我只想以紅色突出顯示上半部分。它下面沒有日曆。使用jQuery切換一年或十二月的年份
我已經實現了這一切,但有毛刺。當你走向未來的幾個月時,它會在十二月份改變這一年。它應該改變1月份的一年。和你回去時一樣。你可以在這裏看到活生生的例子...... Fiddle
這裏是我的jQuery代碼:
var $months = [
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"];
var d = new Date();
var $m = d.getMonth() + 1;
var $y = d.getFullYear();
$('.history-months').click(function() {
var month_num = $('.months').attr('month-count');
var year_num = $('.years').text();
var history_month = parseFloat(month_num) - 1;
$('.months').attr("month-count", history_month);
$('.months').text($months[history_month]);
if (month_num < 3) {
$('.months').attr("month-count", 13);
var history_year = parseFloat(year_num) - 1;
$('.years').text(history_year);
}
});
$('.future-months').click(function() {
var month_num = $('.months').attr('month-count');
var year_num = $('.years').text();
var future_month = parseFloat(month_num) + 1;
$('.months').attr("month-count", future_month);
$('.months').text($months[future_month]);
if (month_num > 10) {
$('.months').attr("month-count", 0);
var history_year = parseFloat(year_num) + 1;
$('.years').text(history_year);
}
});
$('.months').text($months[$m]).attr('month-count', $m);
$('.years').text($y);
這裏是HTML:
<a href="#" class="history-months"><</a>
<span class="months-years">
<span class="months"></span>
<span class="years"></span>
</span>
<a href="#" class="future-months">></a>
任何想法?
感謝
奧馬爾