?? 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 + -