243 lines
8.1 KiB
JavaScript
243 lines
8.1 KiB
JavaScript
|
$(document).ready(function() {
|
||
|
// 默认显示第一个选项卡
|
||
|
$(".tabcontent").hide();
|
||
|
$("#Tab1").show();
|
||
|
$(".tablinks").first().addClass("active");
|
||
|
|
||
|
// 点击选项卡按钮时切换内容
|
||
|
$(".tablinks").click(function() {
|
||
|
var tabName = $(this).data("tab");
|
||
|
|
||
|
// 隐藏所有选项卡内容
|
||
|
$(".tabcontent").hide();
|
||
|
|
||
|
// 显示当前选项卡内容
|
||
|
$("#" + tabName).show();
|
||
|
|
||
|
// 移除所有按钮的活动状态
|
||
|
$(".tablinks").removeClass("active");
|
||
|
|
||
|
// 设置当前按钮为活动状态
|
||
|
$(this).addClass("active");
|
||
|
});
|
||
|
|
||
|
// 添加新选项卡
|
||
|
$("#addTab").click(function() {
|
||
|
var newTabId = "Tab" + ($(".tablinks").length + 1);
|
||
|
var newTabButton = `<button class="tablinks" data-tab="${newTabId}">第${$(".tablinks").length}张照片</button>`;
|
||
|
var newTabContent = `
|
||
|
<div id="${newTabId}" class="tabcontent">
|
||
|
<button class="removeTab" data-tab="${newTabId}">x</button>
|
||
|
<h3>第${$(".tablinks").length}张照片</h3>
|
||
|
<img style="max-width:100%;overflow:hidden;" src="./jpg/${$(".tablinks").length}.jpg" alt="第${$(".tablinks").length}张照片">
|
||
|
</div>
|
||
|
`;
|
||
|
|
||
|
$(".tab").find(".addTab").before(newTabButton);
|
||
|
$("body").append(newTabContent);
|
||
|
|
||
|
// 绑定新添加的选项卡按钮和删除按钮的事件
|
||
|
bindTabEvents();
|
||
|
});
|
||
|
|
||
|
// 删除选项卡
|
||
|
$(document).on("click", ".removeTab", function() {
|
||
|
var tabName = $(this).data("tab");
|
||
|
$("#" + tabName).remove();
|
||
|
$("button[data-tab='" + tabName + "']").remove();
|
||
|
|
||
|
// 显示第一个选项卡内容
|
||
|
$(".tabcontent").hide();
|
||
|
$(".tablinks").first().addClass("active");
|
||
|
$("#" + $(".tablinks").first().data("tab")).show();
|
||
|
});
|
||
|
|
||
|
// 绑定选项卡按钮和删除按钮的事件
|
||
|
function bindTabEvents() {
|
||
|
$(".tablinks").off("click").click(function() {
|
||
|
var tabName = $(this).data("tab");
|
||
|
|
||
|
// 隐藏所有选项卡内容
|
||
|
$(".tabcontent").hide();
|
||
|
|
||
|
// 显示当前选项卡内容
|
||
|
$("#" + tabName).show();
|
||
|
|
||
|
// 移除所有按钮的活动状态
|
||
|
$(".tablinks").removeClass("active");
|
||
|
|
||
|
// 设置当前按钮为活动状态
|
||
|
$(this).addClass("active");
|
||
|
});
|
||
|
|
||
|
$(".removeTab").off("click").click(function() {
|
||
|
var tabName = $(this).data("tab");
|
||
|
$("#" + tabName).remove();
|
||
|
$("button[data-tab='" + tabName + "']").remove();
|
||
|
|
||
|
// 显示第一个选项卡内容
|
||
|
$(".tabcontent").hide();
|
||
|
$(".tablinks").first().addClass("active");
|
||
|
$("#" + $(".tablinks").first().data("tab")).show();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 初始绑定事件
|
||
|
bindTabEvents();
|
||
|
$(document).ready(function() {
|
||
|
var date = new Date();
|
||
|
var year = date.getFullYear();
|
||
|
var nowyear = date.getFullYear();
|
||
|
var month = date.getMonth() + 1;
|
||
|
var nowmonth = date.getMonth() + 1;
|
||
|
var dateday = date.getDate();
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
|
||
|
function showcld() {
|
||
|
var monthDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // 创建数组存放每个月有多少天 ,默认2月为28天
|
||
|
// 判断闰年
|
||
|
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||
|
monthDay[1] = 29;
|
||
|
}
|
||
|
// 计算每个月的天数
|
||
|
var days = monthDay[month - 1];
|
||
|
// 判断每月第一天为周几
|
||
|
date.setYear(year); //某年
|
||
|
date.setMonth(month - 1); //某年的某月
|
||
|
date.setDate(1); // 某月的某天
|
||
|
var weekday = date.getDay(); // 判断某天是周几
|
||
|
// 补齐一号前的空格
|
||
|
var tbodyHtml = '<tr>';
|
||
|
for (var i = 0; i < weekday; i++) {
|
||
|
tbodyHtml += "<td></td>";
|
||
|
}
|
||
|
// 补齐每月的日期
|
||
|
var changLine = weekday;
|
||
|
var tagClass = '';
|
||
|
for (i = 1; i <= days; i++) { //每一个日期的填充
|
||
|
if (year == nowyear && month == nowmonth && i == dateday) {
|
||
|
tagClass = "curDate"; //当前日期对应格子
|
||
|
} else {
|
||
|
tagClass = "isDate";
|
||
|
}
|
||
|
tbodyHtml += "<td class='" + tagClass + "' data-date='" + year + '-' + month + '-' + i + "'>" + i + "</td>";
|
||
|
changLine = (changLine + 1) % 7;
|
||
|
if (changLine == 0 && i != days) { //是否换行填充的判断
|
||
|
tbodyHtml += "</tr><tr>";
|
||
|
}
|
||
|
}
|
||
|
$('#tbody').empty(); // 清空原有的内容
|
||
|
$('#tbody').append(tbodyHtml); //添加当前月份的日期内容
|
||
|
|
||
|
// 添加点击事件
|
||
|
$('#tbody td').click(function() {
|
||
|
var dateString = $(this).data('date');
|
||
|
document.title = dateString;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 设置按钮点击事件
|
||
|
$('#left').click(function() {
|
||
|
month = month - 1;
|
||
|
if (month < 1) {
|
||
|
month = 12;
|
||
|
year--;
|
||
|
}
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
showcld();
|
||
|
});
|
||
|
|
||
|
$('#right').click(function() {
|
||
|
month = month + 1;
|
||
|
if (month > 12) {
|
||
|
month = 1;
|
||
|
year++;
|
||
|
}
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
showcld();
|
||
|
});
|
||
|
|
||
|
showcld(); //页面加载后执行函数
|
||
|
});
|
||
|
$(document).ready(function() {
|
||
|
var date = new Date();
|
||
|
var year = date.getFullYear();
|
||
|
var nowyear = date.getFullYear();
|
||
|
var month = date.getMonth() + 1;
|
||
|
var nowmonth = date.getMonth() + 1;
|
||
|
var dateday = date.getDate();
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
|
||
|
function showcld() {
|
||
|
var monthDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // 创建数组存放每个月有多少天 ,默认2月为28天
|
||
|
// 判断闰年
|
||
|
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||
|
monthDay[1] = 29;
|
||
|
}
|
||
|
// 计算每个月的天数
|
||
|
var days = monthDay[month - 1];
|
||
|
// 判断每月第一天为周几
|
||
|
date.setYear(year); //某年
|
||
|
date.setMonth(month - 1); //某年的某月
|
||
|
date.setDate(1); // 某月的某天
|
||
|
var weekday = date.getDay(); // 判断某天是周几
|
||
|
// 补齐一号前的空格
|
||
|
var tbodyHtml = '<tr>';
|
||
|
for (var i = 0; i < weekday; i++) {
|
||
|
tbodyHtml += "<td></td>";
|
||
|
}
|
||
|
// 补齐每月的日期
|
||
|
var changLine = weekday;
|
||
|
var tagClass = '';
|
||
|
for (i = 1; i <= days; i++) { //每一个日期的填充
|
||
|
if (year == nowyear && month == nowmonth && i == dateday) {
|
||
|
tagClass = "curDate"; //当前日期对应格子
|
||
|
} else {
|
||
|
tagClass = "isDate";
|
||
|
}
|
||
|
tbodyHtml += "<td class='" + tagClass + "' data-date='" + year + '-' + month + '-' + i + "'>" + i + "</td>";
|
||
|
changLine = (changLine + 1) % 7;
|
||
|
if (changLine == 0 && i != days) { //是否换行填充的判断
|
||
|
tbodyHtml += "</tr><tr>";
|
||
|
}
|
||
|
}
|
||
|
$('#tbody').empty(); // 清空原有的内容
|
||
|
$('#tbody').append(tbodyHtml); //添加当前月份的日期内容
|
||
|
|
||
|
// 添加点击事件
|
||
|
$('#tbody td').click(function() {
|
||
|
var dateString = $(this).data('date');
|
||
|
$('#selectedDate').text(dateString);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 设置按钮点击事件
|
||
|
$('#left').click(function() {
|
||
|
month = month - 1;
|
||
|
if (month < 1) {
|
||
|
month = 12;
|
||
|
year--;
|
||
|
}
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
showcld();
|
||
|
});
|
||
|
|
||
|
$('#right').click(function() {
|
||
|
month = month + 1;
|
||
|
if (month > 12) {
|
||
|
month = 1;
|
||
|
year++;
|
||
|
}
|
||
|
var todateHtml = year + '年' + month + '月';
|
||
|
$('#topDate').text(todateHtml);
|
||
|
showcld();
|
||
|
});
|
||
|
|
||
|
showcld(); //页面加载后执行函数
|
||
|
});
|
||
|
});
|