|
<script language="JavaScript">
/**//**
*本日歷選擇控件由tianNET根據(jù)前人經(jīng)驗(yàn)完善而得。大部分代碼來(lái)自meizz的日歷控件。
*tianNET添加了時(shí)間選擇功能、select,object標(biāo)簽隱藏功能,還有其它小功能。
*使用方法:
* (1)只選擇日期 <input type="text" name="date" readOnly onClick="setDay(this);">
* (2)選擇日期和小時(shí) <input type="text" name="dateh" readOnly onClick="setDayH(this);">
* (3)選擇日期和小時(shí)及分鐘 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
*設(shè)置參數(shù)的方法
* (1)設(shè)置日期分隔符 setDateSplit(strSplit);默認(rèn)為"-"
* (2)設(shè)置日期與時(shí)間之間的分隔符 setDateTimeSplit(strSplit);默認(rèn)為" "
* (3)設(shè)置時(shí)間分隔符 setTimeSplit(strSplit);默認(rèn)為":"
* (4)設(shè)置(1),(2),(3)中的分隔符 setSplit(strDateSplit,strDateTimeSplit,strTimeSplit);
* (5)設(shè)置開(kāi)始和結(jié)束年份 setYearPeriod(intDateBeg,intDateEnd)
*說(shuō)明:
* 默認(rèn)返回的日期時(shí)間格式如同:2005-02-02 08:08
*/
//------------------ 樣式定義 ---------------------------//
//功能按鈕同樣樣式
var s_tianNET_turn_base = "height:16px;font-size:9pt;color:white;border:0 solid #CCCCCC;cursor:hand;background-color:#2650A6;";
//翻年、月等的按鈕
var s_tianNET_turn = "width:28px;" + s_tianNET_turn_base;
//關(guān)閉、清空等按鈕樣式
var s_tianNET_turn2 = "width:22px;" + s_tianNET_turn_base;
//年選擇下拉框
var s_tianNET_select = "width:64px;display:none;";
//月、時(shí)、分選擇下拉框
var s_tianNET_select2 = "width:46px;display:none;";
//日期選擇控件體的樣式
var s_tianNET_body = "width:150;background-color:#2650A6;display:none;z-index:9998;position:absolute;" +
"border-left:1 solid #CCCCCC;border-top:1 solid #CCCCCC;border-right:1 solid #999999;border-bottom:1 solid #999999;";
//顯示日的td的樣式
var s_tianNET_day = "width:21px;height:20px;background-color:#D8F0FC;font-size:10pt;";
//字體樣式
var s_tianNET_font = "color:#FFCC00;font-size:9pt;cursor:hand;";
//鏈接的樣式
var s_tianNET_link = "text-decoration:none;font-size:9pt;color:#2650A6;";
//橫線(xiàn)
var s_tianNET_line = "border-bottom:1 solid #6699CC";
//------------------ 變量定義 ---------------------------//
var tianNETYearSt = 1950;//可選擇的開(kāi)始年份
var tianNETYearEnd = 2010;//可選擇的結(jié)束年份
var tianNETDateNow = new Date();
var tianNETYear = tianNETDateNow.getFullYear(); //定義年的變量的初始值
var tianNETMonth = tianNETDateNow.getMonth()+1; //定義月的變量的初始值
var tianNETDay = tianNETDateNow.getDate();
var tianNETHour = 8;//tianNETDateNow.getHours();
var tianNETMinute = 0;//tianNETDateNow.getMinutes();
var tianNETArrDay=new Array(42); //定義寫(xiě)日期的數(shù)組
var tianNETDateSplit = "-"; //日期的分隔符號(hào)
var tianNETDateTimeSplit = " "; //日期與時(shí)間之間的分隔符
var tianNETTimeSplit = ":"; //時(shí)間的分隔符號(hào)
var tianNETOutObject; //接收日期時(shí)間的對(duì)象
var arrTianNETHide = new Array();//被強(qiáng)制隱藏的標(biāo)簽
var m_bolShowHour = false;//是否顯示小時(shí)
var m_bolShowMinute = false;//是否顯示分鐘
var m_aMonHead = new Array(12); //定義陽(yáng)歷中每個(gè)月的最大天數(shù)
m_aMonHead[0] = 31; m_aMonHead[1] = 28; m_aMonHead[2] = 31; m_aMonHead[3] = 30; m_aMonHead[4] = 31; m_aMonHead[5] = 30;
m_aMonHead[6] = 31; m_aMonHead[7] = 31; m_aMonHead[8] = 30; m_aMonHead[9] = 31; m_aMonHead[10] = 30; m_aMonHead[11] = 31;
// ---------------------- 用戶(hù)可調(diào)用的函數(shù) -----------------------------//
//用戶(hù)主調(diào)函數(shù)-只選擇日期
function setDay(obj){
tianNETOutObject = obj;
//如果標(biāo)簽中有值,則將日期初始化為當(dāng)前值
var strValue = tianNETTrim(tianNETOutObject.value);
if( strValue != "" ){
tianNETInitDate(strValue);
}
tianNETPopCalendar();
}
//用戶(hù)主調(diào)函數(shù)-選擇日期和小時(shí)
function setDayH(obj){
tianNETOutObject = obj;
m_bolShowHour = true;
//如果標(biāo)簽中有值,則將日期和小時(shí)初始化為當(dāng)前值
var strValue = tianNETTrim(tianNETOutObject.value);
if( strValue != "" ){
tianNETInitDate(strValue.substring(0,10));
var hour = strValue.substring(11,13);
if( hour < 10 ) tianNETHour = hour.substring(1,2);
}
tianNETPopCalendar();
}
//用戶(hù)主調(diào)函數(shù)-選擇日期和小時(shí)及分鐘
function setDayHM(obj){
tianNETOutObject = obj;
m_bolShowHour = true;
m_bolShowMinute = true;
//如果標(biāo)簽中有值,則將日期和小時(shí)及分鐘初始化為當(dāng)前值
var strValue = tianNETTrim(tianNETOutObject.value);
if( strValue != "" ){
tianNETInitDate(strValue.substring(0,10));
var time = strValue.substring(11,16);
var arr = time.split(tianNETTimeSplit);
tianNETHour = arr[0];
tianNETMinute = arr[1];
if( tianNETHour < 10 ) tianNETHour = tianNETHour.substring(1,2);
if( tianNETMinute < 10 ) tianNETMinute = tianNETMinute.substring(1,2);
}
tianNETPopCalendar();
}
//設(shè)置開(kāi)始日期和結(jié)束日期
function setYearPeriod(intDateBeg,intDateEnd){
tianNETYearSt = intDateBeg;
tianNETYearEnd = intDateEnd;
}
//設(shè)置日期分隔符。默認(rèn)為"-"
function setDateSplit(strDateSplit){
tianNETDateSplit = strDateSplit;
}
//設(shè)置日期與時(shí)間之間的分隔符。默認(rèn)為" "
function setDateTimeSplit(strDateTimeSplit){
tianNETDateTimeSplit = strDateTimeSplit;
}
//設(shè)置時(shí)間分隔符。默認(rèn)為":"
function setTimeSplit(strTimeSplit){
tianNETTimeSplit = strTimeSplit;
}
//設(shè)置分隔符
function setSplit(strDateSplit,strDateTimeSplit,strTimeSplit){
tianNETDateSplit(strDateSplit);
tianNETDateTimeSplit(strDateTimeSplit);
tianNETTimeSplit(strTimeSplit);
}
//設(shè)置默認(rèn)的日期。格式為:YYYY-MM-DD
function setDefaultDate(strDate){
tianNETYear = strDate.substring(0,4);
tianNETMonth = strDate.substring(5,7);
tianNETDay = strDate.substring(8,10);
}
//設(shè)置默認(rèn)的時(shí)間。格式為:HH24:MI
function setDefaultTime(strTime){
tianNETHour = strTime.substring(0,2);
tianNETMinute = strTime.substring(3,5);
}
// ---------------------- end 用戶(hù)可調(diào)用的函數(shù) -----------------------------//
//------------------ begin 頁(yè)面顯示部分 ---------------------------//
var weekName = new Array("日","一","二","三","四","五","六");
document.write('<div id="divTianNETDate" style="'+s_tianNET_body+'" style="本日歷選擇控件由tianNET根據(jù)前人經(jīng)驗(yàn)完善而成!">');
document.write('<div align="center" id="divTianNETDateText" Author="tianNET" style="padding-top:2px;">');
document.write('<span id="tianNETYearHead" Author="tianNET" style="'+s_tianNET_font+'" '+
'onclick="spanYearCEvent();"> 年</span>');
document.write('<select id="selTianYear" style="'+s_tianNET_select+'" Author="tianNET" '+
' onChange="tianNETYear=this.value;tianNETSetDay(tianNETYear,tianNETMonth);document.all.tianNETYearHead.style.display=/'/';'+
'this.style.display=/'none/';">');
for(var i=tianNETYearSt;i <= tianNETYearEnd;i ++){
document.writeln('<option value="' + i + '">' + i + '年</option>');
}
document.write('</select>');
document.write('<span id="tianNETMonthHead" Author="tianNET" style="'+s_tianNET_font+'" '+
'onclick="spanMonthCEvent();"> 月</span>');
document.write('<select id="selTianMonth" style="'+s_tianNET_select2+'" Author="tianNET" '+
'onChange="tianNETMonth=this.value;tianNETSetDay(tianNETYear,tianNETMonth);document.all.tianNETMonthHead.style.display=/'/';'+
'this.style.display=/'none/';">');
for(var i=1;i <= 12;i ++){
document.writeln('<option value="' + i + '">' + i + '月</option>');
}
document.write('</select>');
//document.write('</div>');
//document.write('<div align="center" id="divTianNETTimeText" Author="tianNET">');
document.write('<span id="tianNETHourHead" Author="tianNET" style="'+s_tianNET_font+'display:none;" '+
'onclick="spanHourCEvent();"> 時(shí)</span>');
document.write('<select id="selTianHour" style="'+s_tianNET_select2+'display:none;" Author="tianNET" '+
' onChange="tianNETHour=this.value;tianNETWriteHead();document.all.tianNETHourHead.style.display=/'/';' +
'this.style.display=/'none/';">');
for(var i=0;i <= 23;i ++){
document.writeln('<option value="' + i + '">' + i + '時(shí)</option>');
}
document.write('</select>');
document.write('<span id="tianNETMinuteHead" Author="tianNET" style="'+s_tianNET_font+'display:none;" '+
'onclick="spanMinuteCEvent();"> 分</span>');
document.write('<select id="selTianMinute" style="'+s_tianNET_select2+'display:none;" Author="tianNET" '+
' onChange="tianNETMinute=this.value;tianNETWriteHead();document.all.tianNETMinuteHead.style.display=/'/';'+
'this.style.display=/'none/';">');
for(var i=0;i <= 59;i ++){
document.writeln('<option value="' + i + '">' + i + '分</option>');
}
document.write('</select>');
document.write('</div>');
//輸出一條橫線(xiàn)
document.write('<div style="'+s_tianNET_line+'"></div>');
document.write('<div align="center" id="divTianNETTurn" style="border:0;" Author="tianNET">');
document.write('<input type="button" style="'+s_tianNET_turn+'" value="年↑" title="上一年" onClick="tianNETPrevYear();">');
document.write('<input type="button" style="'+s_tianNET_turn+'" value="年↓" title="下一年" onClick="tianNETNextYear();"> ');
document.write('<input type="button" style="'+s_tianNET_turn+'" value="月↑" title="上一月" onClick="tianNETPrevMonth();">');
document.write('<input type="button" style="'+s_tianNET_turn+'" value="月↓" title="下一月" onClick="tianNETNextMonth();">');
document.write('</div>');
//輸出一條橫線(xiàn)
document.write('<div style="'+s_tianNET_line+'"></div>');
document.write('<table border=0 cellspacing=0 cellpadding=0 bgcolor=white onselectstart="return false">');
document.write(' <tr style="background-color:#2650A6;font-size:10pt;color:white;height:22px;" Author="tianNET">');
for(var i =0;i < weekName.length;i ++){
//輸出星期
document.write('<td width="21" align="center" Author="tianNET">' + weekName[i] + '</td>');
}
document.write(' </tr>');
document.write('</table>');
//輸出天的選擇
document.write('<table border=0 cellspacing=1 cellpadding=0 bgcolor=white onselectstart="return false">');
var n = 0;
for (var i=0;i<5;i++) {
document.write (' <tr align=center id="trTianNETDay' + i + '" >');
for (var j=0;j<7;j++){
document.write('<td align="center" id="tdTianNETDay' + n + '" '+
'onClick="tianNETDay=this.innerText;tianNETSetValue(true);" '
+' style="' + s_tianNET_day + '"> </td>');
n ++;
}
document.write (' </tr>');
}
document.write (' <tr align=center id="trTianNETDay5" >');
document.write('<td align="center" id="tdTianNETDay35" onClick="tianNETDay=this.innerText;tianNETSetValue(true);" '
+' style="' + s_tianNET_day + '"> </td>');
document.write('<td align="center" id="tdTianNETDay36" onClick="tianNETDay=this.innerText;tianNETSetValue(true);" '
+' style="' + s_tianNET_day + '"> </td>');
document.write('<td align="right" colspan="5"><a href="Javascript:tianNETClear();" style="' + s_tianNET_link + '">清空</a>'+
' <a href="Javascript:tianNETHideControl();" style="' + s_tianNET_link + '">關(guān)閉</a>' +
' <a href="Javascript:tianNETSetValue(true);" style="' + s_tianNET_link + '">確定</a> ' +
'</td>');
document.write (' </tr>');
document.write('</table>');
document.write('</div>');
//------------------ end 頁(yè)面顯示部分 ---------------------------//
//------------------ 顯示日期時(shí)間的span標(biāo)簽響應(yīng)事件 ---------------------------//
//單擊年份span標(biāo)簽響應(yīng)
function spanYearCEvent(){
hideElementsById(new Array("selTianYear","tianNETMonthHead"),false);
if(m_bolShowHour) hideElementsById(new Array("tianNETHourHead"),false);
if(m_bolShowMinute) hideElementsById(new Array("tianNETMinuteHead"),false);
hideElementsById(new Array("tianNETYearHead","selTianMonth","selTianHour","selTianMinute"),true);
}
//單擊月份span標(biāo)簽響應(yīng)
function spanMonthCEvent(){
hideElementsById(new Array("selTianMonth","tianNETYearHead"),false);
if(m_bolShowHour) hideElementsById(new Array("tianNETHourHead"),false);
if(m_bolShowMinute) hideElementsById(new Array("tianNETMinuteHead"),false);
hideElementsById(new Array("tianNETMonthHead","selTianYear","selTianHour","selTianMinute"),true);
}
//單擊小時(shí)span標(biāo)簽響應(yīng)
function spanHourCEvent(){
hideElementsById(new Array("tianNETYearHead","tianNETMonthHead"),false);
if(m_bolShowHour) hideElementsById(new Array("selTianHour"),false);
if(m_bolShowMinute) hideElementsById(new Array("tianNETMinuteHead"),false);
hideElementsById(new Array("tianNETHourHead","selTianYear","selTianMonth","selTianMinute"),true);
}
//單擊分鐘span標(biāo)簽響應(yīng)
function spanMinuteCEvent(){
hideElementsById(new Array("tianNETYearHead","tianNETMonthHead"),false);
if(m_bolShowHour) hideElementsById(new Array("tianNETHourHead"),false);
if(m_bolShowMinute) hideElementsById(new Array("selTianMinute"),false);
hideElementsById(new Array("tianNETMinuteHead","selTianYear","selTianMonth","selTianHour"),true);
}
//根據(jù)標(biāo)簽id隱藏或顯示標(biāo)簽
function hideElementsById(arrId,bolHide){
var strDisplay = "";
if(bolHide) strDisplay = "none";
for(var i = 0;i < arrId.length;i ++){
var obj = document.getElementById(arrId[i]);
obj.style.display = strDisplay;
}
}
//------------------ end 顯示日期時(shí)間的span標(biāo)簽響應(yīng)事件 ---------------------------//
//判斷某年是否為閏年
function isPinYear(year){
var bolRet = false;
if (0==year%4&&((year%100!=0)||(year%400==0))) {
bolRet = true;
}
return bolRet;
}
//得到一個(gè)月的天數(shù),閏年為29天
function getMonthCount(year,month){
var c=m_aMonHead[month-1];
if((month==2)&&isPinYear(year)) c++;
return c;
}
//重新設(shè)置當(dāng)前的日。主要是防止在翻年、翻月時(shí),當(dāng)前日大于當(dāng)月的最大日
function setRealDayCount() {
if( tianNETDay > getMonthCount(tianNETYear,tianNETMonth) ) {
//如果當(dāng)前的日大于當(dāng)月的最大日,則取當(dāng)月最大日
tianNETDay = getMonthCount(tianNETYear,tianNETMonth);
}
}
//在個(gè)位數(shù)前加零
function addZero(value){
if(value < 10 ){
value = "0" + value;
}
return value;
}
//取出空格
function tianNETTrim(str) {
return str.replace(/(^/s*)|(/s*$)/g,"");
}
//為select創(chuàng)建一個(gè)option
function createOption(objSelect,value,text){
var option = document.createElement("OPTION");
option.value = value;
option.text = text;
objSelect.options.add(option);
}
//往前翻 Year
function tianNETPrevYear() {
if(tianNETYear > 999 && tianNETYear <10000){tianNETYear--;}
else{alert("年份超出范圍(1000-9999)!");}
tianNETSetDay(tianNETYear,tianNETMonth);
//如果年份小于允許的最小年份,則創(chuàng)建對(duì)應(yīng)的option
if( tianNETYear < tianNETYearSt ) {
tianNETYearSt = tianNETYear;
createOption(document.all.selTianYear,tianNETYear,tianNETYear + "年");
}
checkSelect(document.all.selTianYear,tianNETYear);
tianNETWriteHead();
}
//往后翻 Year
function tianNETNextYear() {
if(tianNETYear > 999 && tianNETYear <10000){tianNETYear++;}
else{alert("年份超出范圍(1000-9999)!");return;}
tianNETSetDay(tianNETYear,tianNETMonth);
//如果年份超過(guò)允許的最大年份,則創(chuàng)建對(duì)應(yīng)的option
if( tianNETYear > tianNETYearEnd ) {
tianNETYearEnd = tianNETYear;
createOption(document.all.selTianYear,tianNETYear,tianNETYear + "年");
}
checkSelect(document.all.selTianYear,tianNETYear);
tianNETWriteHead();
}
//選擇今天
function tianNETToday() {
tianNETYear = tianNETDateNow.getFullYear();
tianNETMonth = tianNETDateNow.getMonth()+1;
tianNETDay = tianNETDateNow.getDate();
tianNETSetValue(true);
//tianNETSetDay(tianNETYear,tianNETMonth);
//selectObject();
}
//往前翻月份
function tianNETPrevMonth() {
if(tianNETMonth>1){tianNETMonth--}else{tianNETYear--;tianNETMonth=12;}
tianNETSetDay(tianNETYear,tianNETMonth);
checkSelect(document.all.selTianMonth,tianNETMonth);
tianNETWriteHead();
}
//往后翻月份
function tianNETNextMonth() {
if(tianNETMonth==12){tianNETYear++;tianNETMonth=1}else{tianNETMonth++}
tianNETSetDay(tianNETYear,tianNETMonth);
checkSelect(document.all.selTianMonth,tianNETMonth);
tianNETWriteHead();
}
//向span標(biāo)簽中寫(xiě)入年、月、時(shí)、分等數(shù)據(jù)
function tianNETWriteHead(){
document.all.tianNETYearHead.innerText = tianNETYear + "年";
document.all.tianNETMonthHead.innerText = tianNETMonth + "月";
if( m_bolShowHour ) document.all.tianNETHourHead.innerText = " "+tianNETHour + "時(shí)";
if( m_bolShowMinute ) document.all.tianNETMinuteHead.innerText = tianNETMinute + "分";
tianNETSetValue(false);//給文本框賦值,但不隱藏本控件
}
//設(shè)置顯示天
function tianNETSetDay(yy,mm) {
setRealDayCount();//設(shè)置當(dāng)月真實(shí)的日
tianNETWriteHead();
var strDateFont1 = "", strDateFont2 = "" //處理日期顯示的風(fēng)格
for (var i = 0; i < 37; i++){tianNETArrDay[i]=""}; //將顯示框的內(nèi)容全部清空
var day1 = 1;
var firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期幾
for (var i = firstday; day1 < getMonthCount(yy,mm)+1; i++){
tianNETArrDay[i]=day1;day1++;
}
//如果用于顯示日的最后一行的第一個(gè)單元格的值為空,則隱藏整行。
//if(tianNETArrDay[35] == ""){
// document.all.trTianNETDay5.style.display = "none";
//} else {
// document.all.trTianNETDay5.style.display = "";
//}
for (var i = 0; i < 37; i++){
var da = eval("document.all.tdTianNETDay"+i) //書(shū)寫(xiě)新的一個(gè)月的日期星期排列
if (tianNETArrDay[i]!="") {
//判斷是否為周末,如果是周末,則改為紅色字體
if(i % 7 == 0 || (i+1) % 7 == 0){
strDateFont1 = "<font color=#f0000>"
strDateFont2 = "</font>"
} else {
strDateFont1 = "";
strDateFont2 = ""
}
da.innerHTML = strDateFont1 + tianNETArrDay[i] + strDateFont2;
//如果是當(dāng)前選擇的天,則改變顏色
if(tianNETArrDay[i] == tianNETDay ) {
da.style.backgroundColor = "#CCCCCC";
} else {
da.style.backgroundColor = "#EFEFEF";
}
da.style.cursor="hand"
} else {
da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"
}
}//end for
tianNETSetValue(false);//給文本框賦值,但不隱藏本控件
}//end function tianNETSetDay
//根據(jù)option的值選中option
function checkSelect(objSelect,selectValue) {
var count = parseInt(objSelect.length);
if( selectValue < 10 && selectValue.toString().length == 2) {
selectValue = selectValue.substring(1,2);
}
for(var i = 0;i < count;i ++){
if(objSelect.options[i].value == selectValue){
objSelect.selectedIndex = i;
break;
}
}//for
}
//選中年、月、時(shí)、分等下拉框
function selectObject(){
//如果年份小于允許的最小年份,則創(chuàng)建對(duì)應(yīng)的option
if( tianNETYear < tianNETYearSt ) {
for( var i = tianNETYear;i < tianNETYearSt;i ++ ){
createOption(document.all.selTianYear,i,i + "年");
}
tianNETYearSt = tianNETYear;
}
//如果年份超過(guò)允許的最大年份,則創(chuàng)建對(duì)應(yīng)的option
if( tianNETYear > tianNETYearEnd ) {
for( var i = tianNETYearEnd+1;i <= tianNETYear;i ++ ){
createOption(document.all.selTianYear,i,i + "年");
}
tianNETYearEnd = tianNETYear;
}
checkSelect(document.all.selTianYear,tianNETYear);
checkSelect(document.all.selTianMonth,tianNETMonth);
if( m_bolShowHour ) checkSelect(document.all.selTianHour,tianNETHour);
if( m_bolShowMinute ) checkSelect(document.all.selTianMinute,tianNETMinute);
}
//給接受日期時(shí)間的控件賦值
//參數(shù)bolHideControl - 是否隱藏控件
function tianNETSetValue(bolHideControl){
var value = "";
if( !tianNETDay || tianNETDay == "" ){
tianNETOutObject.value = value;
return;
}
var mm = tianNETMonth;
var day = tianNETDay;
if( mm < 10 && mm.toString().length == 1) mm = "0" + mm;
if( day < 10 && day.toString().length == 1) day = "0" + day;
value = tianNETYear + tianNETDateSplit + mm + tianNETDateSplit + day;
if( m_bolShowHour ){
var hour = tianNETHour;
if( hour < 10 && hour.toString().length == 1 ) hour = "0" + hour;
value += tianNETDateTimeSplit + hour;
}
if( m_bolShowMinute ){
var minute = tianNETMinute;
if( minute < 10 && minute.toString().length == 1 ) minute = "0" + minute;
value += tianNETTimeSplit + minute;
}
tianNETOutObject.value = value;
//document.all.divTianNETDate.style.display = "none";
if( bolHideControl ) {
tianNETHideControl();
}
}
//是否顯示時(shí)間
function showTime(){
if( !m_bolShowHour && m_bolShowMinute){
alert("如果要選擇分鐘,則必須可以選擇小時(shí)!");
return;
}
hideElementsById(new Array("tianNETHourHead","selTianHour","tianNETMinuteHead","selTianMinute"),true);
if( m_bolShowHour ){
//顯示小時(shí)
hideElementsById(new Array("tianNETHourHead"),false);
}
if( m_bolShowMinute ){
//顯示分鐘
hideElementsById(new Array("tianNETMinuteHead"),false);
}
}
//彈出顯示日歷選擇控件,以讓用戶(hù)選擇
function tianNETPopCalendar(){
//隱藏下拉框,顯示相對(duì)應(yīng)的head
hideElementsById(new Array("selTianYear","selTianMonth","selTianHour","selTianMinute"),true);
hideElementsById(new Array("tianNETYearHead","tianNETMonthHead","tianNETHourHead","tianNETMinuteHead"),false);
tianNETSetDay(tianNETYear,tianNETMonth);
tianNETWriteHead();
showTime();
var dads = document.all.divTianNETDate.style;
var iX, iY;
var h = document.all.divTianNETDate.offsetHeight;
var w = document.all.divTianNETDate.offsetWidth;
//計(jì)算left
if (window.event.x + h > document.body.offsetWidth - 10 )
iX = window.event.x - h - 5 ;
else
iX = window.event.x + 5;
if (iX <0)
iX=0;
//計(jì)算top
iY = window.event.y;
if (window.event.y + w > document.body.offsetHeight - 10 )
iY = document.body.scrollTop + document.body.offsetHeight - w - 5 ;
else
iY = document.body.scrollTop +window.event.y + 5;
if (iY <0)
iY=0;
dads.left = iX;
dads.top = iY;
tianNETShowControl();
selectObject();
}
//隱藏日歷控件(同時(shí)顯示被強(qiáng)制隱藏的標(biāo)簽)
function tianNETHideControl(){
document.all.divTianNETDate.style.display = "none";
tianNETShowObject();
arrTianNETHide = new Array();//將被隱藏的標(biāo)簽對(duì)象清空
}
//顯示日歷控件(同時(shí)隱藏會(huì)遮擋的標(biāo)簽)
function tianNETShowControl(){
document.all.divTianNETDate.style.display = "";
tianNETHideObject("SELECT");
tianNETHideObject("OBJECT");
}
//根據(jù)標(biāo)簽名稱(chēng)隱藏標(biāo)簽。如會(huì)遮住控件的select,object
function tianNETHideObject(strTagName) {
x = document.all.divTianNETDate.offsetLeft;
y = document.all.divTianNETDate.offsetTop;
h = document.all.divTianNETDate.offsetHeight;
w = document.all.divTianNETDate.offsetWidth;
for (var i = 0; i < document.all.tags(strTagName).length; i++)
{
var obj = document.all.tags(strTagName)[i];
if (! obj || ! obj.offsetParent)
continue;
// 獲取元素對(duì)于BODY標(biāo)記的相對(duì)坐標(biāo)
var objLeft = obj.offsetLeft;
var objTop = obj.offsetTop;
var objHeight = obj.offsetHeight;
var objWidth = obj.offsetWidth;
var objParent = obj.offsetParent;
while (objParent.tagName.toUpperCase() != "BODY"){
objLeft += objParent.offsetLeft;
objTop += objParent.offsetTop;
objParent = objParent.offsetParent;
}
//alert("控件左端:" + x + "select左端" + (objLeft + objWidth) + "控件底部:" + (y+h) + "select高:" + objTop);
var bolHide = true;
if( obj.style.display == "none" || obj.style.visibility == "hidden" || obj.getAttribute("Author") == "tianNET" ){
//如果標(biāo)簽本身就是隱藏的,則不需要再隱藏。如果是控件中的下拉框,也不用隱藏。
bolHide = false;
}
if( ( (objLeft + objWidth) > x && (y + h + 20) > objTop && (objTop+objHeight) > y && objLeft < (x+w) ) && bolHide ){
//arrTianNETHide.push(obj);//記錄被隱藏的標(biāo)簽對(duì)象
arrTianNETHide[arrTianNETHide.length] = obj;
obj.style.visibility = "hidden";
}
}
}
//顯示被隱藏的標(biāo)簽
function tianNETShowObject(){
for(var i = 0;i < arrTianNETHide.length;i ++){
//alert(arrTianNETHide[i]);
arrTianNETHide[i].style.visibility = "";
}
}
//初始化日期。
function tianNETInitDate(strDate){
var arr = strDate.split(tianNETDateSplit);
tianNETYear = arr[0];
tianNETMonth = arr[1];
tianNETDay = arr[2];
}
//清空
function tianNETClear(){
tianNETOutObject.value = "";
tianNETHideControl();
}
//任意點(diǎn)擊時(shí)關(guān)閉該控件
function document.onclick(){
with(window.event.srcElement){
if (tagName != "INPUT" && getAttribute("Author") != "tianNET")
tianNETHideControl();
}
}
//按ESC鍵關(guān)閉該控件
function document.onkeypress(){
if( event.keyCode == 27 ){
tianNETHideControl();
}
}
</script>
(1)只選擇日期 <input type="text" name="date" readOnly onClick="setDay(this);"><br/>
(2)選擇日期和小時(shí) <input type="text" name="dateh" readOnly onClick="setDayH(this);"><br/>
(3)選擇日期和小時(shí)及分鐘 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
<p>
金額匯總
</p>
JavaScript技術(shù):日期 時(shí)間js控件,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。