📄 parddudatetimepicker.js
字号:
}
//添加当月日期到表格
function appendDay(){
clearDayInTable(); //清楚之前现实的月份
var parddu_dayNum = 0;//当前月份有多少天
var parddu_onedayOfWeek = 0;//当月的第一天是星期几0-6
//取得当前的年份和月份
var parddu_year = parddu_year_txt.value;
var parddu_month = parddu_month_txt.value;
var parddu_daylist = [31,0,31,30,31,30,31,31,30,31,30,31];
if(parddu_month!=2){
parddu_dayNum = parddu_daylist[parddu_month-1];
}
else{
if((parddu_year%4==0 && parddu_year%100!=0) || parddu_year%400==0){
parddu_dayNum=29;
}
else{
parddu_dayNum=28;
}
}
var temp_date = new Date(parddu_year,parddu_month-1,1);
parddu_onedayOfweek = temp_date.getDay();
//添加日期
var tempTr = false; //临时的行
var loopDay = 0;
for(var temp_i = 0 ;loopDay<parddu_dayNum;temp_i++){
if(temp_i%7==0){
tempTr = parddu_timeTable.insertRow();
tempTr.align="center";
}
var tempTd = tempTr.insertCell();
if(temp_i<parddu_onedayOfweek){
tempTd.innerText=" ";
}
else{
loopDay++;
if(loopDay<10){
tempTd.innerText="0"+loopDay;
}
else{
tempTd.innerText=loopDay;
}
tempTd.style.cursor="hand";
var now = new Date();
var nowYear = now.getYear();
var nowMonth = now.getMonth()+1;
var nowDate = now.getDate();
if(parddu_year_txt.value==nowYear && parddu_month_txt.value==nowMonth && loopDay==nowDate){
tempTd.style.color="red";
}
tempTd.onmouseover = mouseover;
tempTd.onmouseout = mouseout;
tempTd.onclick = mouseclick;
}
}
//添加一个横线
var lineTr = parddu_timeTable.insertRow();
var lineTd = lineTr.insertCell();
lineTd.height="1";
lineTd.colSpan="7";
lineTd.style.backgroundColor="#993366";
}
//当时,分,秒文本框失去焦点时验证时间是否符合要求
function timeTxtBlue(){
var temptxt = event.srcElement;
if(!judgeInputTime(temptxt.value,temptxt.id)){
alert("时间值不符合要求,请重新输入!");
temptxt.select();
temptxt.focus();
}
}
//鼠标点击表格列
function mouseclick(){
var tempTd = event.srcElement;
outputTime(tempTd.innerText);
}
//鼠标悬停表格列
function mouseover(){
var tempTd = event.srcElement;
tempTd.style.fontWeight="bold";
tempTd.style.fontSize="13px";
tempTd.style.backgroundColor = "#aabbfc";
}
//鼠标移出表格列
function mouseout(){
var tempTd = event.srcElement;
tempTd.style.fontWeight="";
tempTd.style.fontSize="12px";
tempTd.style.backgroundColor = "#ffffff";
}
//设置按钮样式1
function setButtonStyleOne(tempbut){
tempbut.style.borderWidth="1px";
tempbut.style.borderColor="#003366";
tempbut.style.backgroundColor="#6699cc";
tempbut.style.fontWeight="";
tempbut.style.fontSize="12px";
tempbut.style.color="#000000";
}
//设置按钮样式2
function setButtonStyleTwo(tempbut){
tempbut.style.borderWidth="1px";
tempbut.style.backgroundColor="#abedac";
tempbut.style.fontSize="12px";
tempbut.style.fontWeight="bold";
tempbut.style.color="red";
}
//文本框样式1
function setTextStyleOne(temptxt){
temptxt.style.borderWidth="0px";
temptxt.style.textAlign="right";
temptxt.style.backgroundColor="transparent";
temptxt.style.color="blue";
}
//文本框样式1
function setTextStyleTwo(temptxt){
temptxt.style.borderLeftWidth="0px";
temptxt.style.borderTopWidth="0px";
temptxt.style.borderRightWidth="0px";
temptxt.style.borderBottomWidth="1px";
temptxt.style.borderBottomColor="#6699cc";
temptxt.style.textAlign="right";
temptxt.style.backgroundColor="transparent";
temptxt.style.color="blue";
}
//鼠标悬停按钮
function mouseOverBut(){
var tempbut = event.srcElement;
setButtonStyleTwo(tempbut);
}
//鼠标移出按钮样式
function mouseOutBut(){
var tempbut = event.srcElement;
setButtonStyleOne(tempbut);
}
//得到当前时间
function setNowTime(){
var now = new Date();
var nowYear = now.getYear();
var nowMonth = now.getMonth()+1;
var nowDate = now.getDate();
var nowDay = now.getDay();
var nowHour = now.getHours();
var nowMinute = now.getMinutes();
var nowSecond = now.getSeconds();
parddu_year_txt.value=nowYear;
parddu_month_txt.value=nowMonth;
parddu_hour_txt.value=judgeTwoLength(nowHour+"");
parddu_minute_txt.value=judgeTwoLength(nowMinute+"");
parddu_second_txt.value=judgeTwoLength(nowSecond+"");
setDisplayNowTimeDiv();
}
//刷新当前时间
function setDisplayNowTimeDiv(){
if(parddu_nowTime!=false && parddu_nowTime!=null){
var now = new Date();
var nowYear = now.getYear();
var nowMonth = now.getMonth()+1;
var nowDate = now.getDate();
var nowDay = now.getDay();
var nowHour = now.getHours();
var nowMinute = now.getMinutes();
var nowSecond = now.getSeconds();
var temp_weekList = ["日","一","二","三","四","五","六"];
var nowStr = nowYear+"-"
nowStr += judgeTwoLength(nowMonth+"")+"-";
nowStr += judgeTwoLength(nowDate+"")+" "
nowStr += judgeTwoLength(nowHour+"")+":"
nowStr += judgeTwoLength(nowMinute+"")+":"
nowStr += judgeTwoLength(nowSecond+"");
nowStr += " 星期"+temp_weekList[nowDay];
parddu_nowTime.innerText = "当前时间:"+nowStr;
setTimeout("setDisplayNowTimeDiv()",1000);
}
}
//清楚原有的日期列表
function clearDayInTable(){
var parddu_rowList = parddu_timeTable.rows;
for(i=parddu_rowList.length-1;i>1;i--){
parddu_timeTable.deleteRow(i);
}
}
//输出结果
function outputTime(tempdate){
//获得各项时间值
var tempYear = parddu_year_txt.value;
var tempMonth = judgeTwoLength(parddu_month_txt.value);
tempdate = judgeTwoLength(tempdate+"");
var tempHour = parddu_hour_txt.value;
var tempMinute = parddu_minute_txt.value;
var tempSecond = parddu_second_txt.value;
//得到输出格式
var outputStr = parddu_disFormat;
//替换日期格式中的表示符号
//替换年份
outputStr = outputStr.replace("yyyy",tempYear);
outputStr = outputStr.replace("MM",tempMonth);
outputStr = outputStr.replace("dd",tempdate);
outputStr = outputStr.replace("hh",tempHour);
outputStr = outputStr.replace("mm",tempMinute);
outputStr = outputStr.replace("ss",tempSecond);
closeTimePicker();
document.getElementById(parddu_disId).value=outputStr;
}
//输出当前时间
function outputNowDateTime(){
var tempnow = new Date();
//获得各项时间值
var tempYear = tempnow.getYear();
var tempMonth = tempnow.getMonth()+1;
var tempdate = tempnow.getDate();
var tempHour = tempnow.getHours();
var tempMinute = tempnow.getMinutes();
var tempSecond = tempnow.getSeconds();
//得到输出格式
var outputStr = parddu_disFormat;
//替换日期格式中的表示符号
//替换年份
outputStr = outputStr.replace("yyyy",tempYear);
outputStr = outputStr.replace("MM",judgeTwoLength(tempMonth+""));
outputStr = outputStr.replace("dd",judgeTwoLength(tempdate+""));
outputStr = outputStr.replace("hh",judgeTwoLength(tempHour+""));
outputStr = outputStr.replace("mm",judgeTwoLength(tempMinute+""));
outputStr = outputStr.replace("ss",judgeTwoLength(tempSecond+""));
closeTimePicker();
document.getElementById(parddu_disId).value=outputStr;
}
//判断给定字符串是否长度为2,如果不足在前天添加一个0
function judgeTwoLength(tempstr){
if(tempstr.length<2){
return "0"+tempstr;
}
else{
return tempstr;
}
}
//验证时间
function judgeInputTime(value,type){
var judgeTest = false;
//小时
if(type=="parddu_hour"){
judgeTime = /^([01][0-9])|(2[0-3])$/;
}
else{
judgeTime = /^[0-5]?[0-9]$/;
}
return judgeTime.test(value);
}
//显示选择年的层
function displayChangeYear(){
var parddu_temp_year = parddu_year_txt.value;
parddu_year_change_div.style.display="block";
var temp_begin_year = parddu_temp_year-30;
parddu_year_change_sel.options.length=60;
for(var temp_for_i=0 ; temp_for_i<60 ; temp_for_i++){
parddu_year_change_sel.options[temp_for_i] = new Option(temp_for_i+temp_begin_year+1,temp_for_i+temp_begin_year+1);
}
parddu_year_change_sel.value = parddu_temp_year;
}
//关闭选择年的层
function closeChangeYear(){
parddu_year_txt.value = parddu_year_change_sel.value;
parddu_year_change_div.style.display="none";
}
//关闭时间控件
function closeTimePicker(){
parddu_timeDiv.style.display="none";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -