熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS日期和時間選擇控件升級版

2022-06-13   來源: JSP教程 
鑒於網上找到的幾個日期選擇程序有些問題遂著手重寫一個程序添加了時間選擇功能截圖及源碼如下有需要的朋友可以參考下  

  鑒於網上找到的幾個日期選擇程序有些問題遂著手重寫一個程序大部分還是借鑒前人的代碼添加了時間選擇功能隱藏會遮擋控件的標簽selectobject
開始本想使用windowcreatePopup()來彈出日歷的選擇這樣就可以跨過任何標簽

不過做到中途發現用createPopup窗口實現理論上是行不通的
一是因為不在窗體裡單擊任何地方都會關閉窗口而當用下拉框選擇年份時很有可能會單擊到窗體外的地方當然這個可以自己寫select來避免但是比較麻煩
二是窗體的寬度和高度只能在彈出時設置而顯然在選擇不同年月時控件高度是要發生改變的

鑒於上面的原因還是決定采用普通的處理方法
 
Calendarjs:

復制代碼 代碼如下:
/**
*本日歷選擇控件由tiannet根據前人經驗完善而得大部分代碼來自meizz的日歷控件
*tiannet添加了時間選擇功能selectobject標簽隱藏功能還有其它小功能
*使用方法
* ()只選擇日期 <input type="text" name="date" readOnly onClick="setDay(this);">
* ()選擇日期和小時 <input type="text" name="dateh" readOnly onClick="setDayH(this);">
* ()選擇日期和小時及分鐘 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
*設置參數的方法
* ()設置日期分隔符 setDateSplit(strSplit);默認為""
* ()設置日期與時間之間的分隔符 setDateTimeSplit(strSplit);默認為" "
* ()設置時間分隔符 setTimeSplit(strSplit);默認為":"
* ()設置()()()中的分隔符 setSplit(strDateSplitstrDateTimeSplitstrTimeSplit);
* ()設置開始和結束年份 setYearPeriod(intDateBegintDateEnd)
*說明
* 默認返回的日期時間格式如同 :
*/
// 樣式定義 //
//功能按鈕同樣樣式
var s_tiannet_turn_base = "height:px;fontsize:pt;color:white;border: solid #CCCCCC;cursor:hand;backgroundcolor:#A;";
//翻年月等的按鈕
var s_tiannet_turn = "width:px;" + s_tiannet_turn_base;
//關閉清空等按鈕樣式
var s_tiannet_turn = "width:px;" + s_tiannet_turn_base;
//年選擇下拉框
var s_tiannet_select = "width:px;display:none;";
//月分選擇下拉框
var s_tiannet_select = "width:px;display:none;";
//日期選擇控件體的樣式
var s_tiannet_body = "width:;backgroundcolor:#A;display:none;zindex:;position:absolute;" +
"borderleft: solid #CCCCCC;bordertop: solid #CCCCCC;borderright: solid #;borderbottom: solid #;";
//顯示日的td的樣式
var s_tiannet_day = "width:px;height:px;backgroundcolor:#DFFC;fontsize:pt;";
//字體樣式
var s_tiannet_font = "color:#FFCC;fontsize:pt;cursor:hand;";
//鏈接的樣式
var s_tiannet_link = "textdecoration:none;fontsize:pt;color:#A;";
//橫線
var s_tiannet_line = "borderbottom: solid #CC";
// 變量定義 //
var tiannetYearSt = ;//可選擇的開始年份
var tiannetYearEnd = ;//可選擇的結束年份
var tiannetDateNow = new Date();
var tiannetYear = tiannetDateNowgetFullYear(); //定義年的變量的初始值
var tiannetMonth = tiannetDateNowgetMonth()+; //定義月的變量的初始值
var tiannetDay = tiannetDateNowgetDate();
var tiannetHour = ;//tiannetDateNowgetHours();
var tiannetMinute = ;//tiannetDateNowgetMinutes();
var tiannetArrDay=new Array(); //定義寫日期的數組
var tiannetDateSplit = ""; //日期的分隔符號
var tiannetDateTimeSplit = " "; //日期與時間之間的分隔符
var tiannetTimeSplit = ":"; //時間的分隔符號
var tiannetOutObject; //接收日期時間的對象
var arrTiannetHide = new Array();//被強制隱藏的標簽
var m_bolShowHour = false;//是否顯示小時
var m_bolShowMinute = false;//是否顯示分鐘
var m_aMonHead = new Array(); //定義陽歷中每個月的最大天數
m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ;
m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ;
// 用戶可調用的函數 //
//用戶主調函數-只選擇日期
function setDay(obj){
tiannetOutObject = obj;
//如果標簽中有值則將日期初始化為當前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValue);
}
tiannetPopCalendar();
}
//用戶主調函數-選擇日期和小時
function setDayH(obj){
tiannetOutObject = obj;
m_bolShowHour = true;
//如果標簽中有值則將日期和小時初始化為當前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValuesubstring());
var hour = strValuesubstring();
if( hour < ) tiannetHour = hoursubstring();
}
tiannetPopCalendar();
}
//用戶主調函數-選擇日期和小時及分鐘
function setDayHM(obj){
tiannetOutObject = obj;
m_bolShowHour = true;
m_bolShowMinute = true;
//如果標簽中有值則將日期和小時及分鐘初始化為當前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValuesubstring());
var time = strValuesubstring();
var arr = timesplit(tiannetTimeSplit);
tiannetHour = arr[];
tiannetMinute = arr[];
if( tiannetHour < ) tiannetHour = tiannetHoursubstring();
if( tiannetMinute < ) tiannetMinute = tiannetMinutesubstring();
}
tiannetPopCalendar();
}
//設置開始日期和結束日期
function setYearPeriod(intDateBegintDateEnd){
tiannetYearSt = intDateBeg;
tiannetYearEnd = intDateEnd;
}
//設置日期分隔符默認為""
function setDateSplit(strDateSplit){
tiannetDateSplit = strDateSplit;
}
//設置日期與時間之間的分隔符默認為" "
function setDateTimeSplit(strDateTimeSplit){
tiannetDateTimeSplit = strDateTimeSplit;
}
//設置時間分隔符默認為":"
function setTimeSplit(strTimeSplit){
tiannetTimeSplit = strTimeSplit;
}
//設置分隔符
function setSplit(strDateSplitstrDateTimeSplitstrTimeSplit){
tiannetDateSplit(strDateSplit);
tiannetDateTimeSplit(strDateTimeSplit);
tiannetTimeSplit(strTimeSplit);
}
//設置默認的日期格式為YYYYMMDD
function setDefaultDate(strDate){
tiannetYear = strDatesubstring();
tiannetMonth = strDatesubstring();
tiannetDay = strDatesubstring();
}
//設置默認的時間格式為HH:MI
function setDefaultTime(strTime){
tiannetHour = strTimesubstring();
tiannetMinute = strTimesubstring();
}
// end 用戶可調用的函數 //
// begin 頁面顯示部分 //
var weekName = new Array("日""一""二""三""四""五""六");
documentwrite(<div id="divTiannetDate" style="+s_tiannet_body+" style="本日歷選擇控件由tiannet根據前人經驗完善而成!">);
documentwrite(<div align="center" id="divTiannetDateText" Author="tiannet" style="paddingtop:px;">);
documentwrite(<span id="tiannetYearHead" Author="tiannet" style="+s_tiannet_font+" +
onclick="spanYearCEvent();"> 年</span>);
documentwrite(<select id="selTianYear" style="+s_tiannet_select+" Author="tiannet" +
onChange="tiannetYear=thisvalue;tiannetSetDay(tiannetYeartiannetMonth);documentalltiannetYearHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=tiannetYearSt;i <= tiannetYearEnd;i ++){
documentwriteln(<option value=" + i + "> + i + 年</option>);
}
documentwrite(</select>);
documentwrite(<span id="tiannetMonthHead" Author="tiannet" style="+s_tiannet_font+" +
onclick="spanMonthCEvent();">  月</span>);
documentwrite(<select id="selTianMonth" style="+s_tiannet_select+" Author="tiannet" +
onChange="tiannetMonth=thisvalue;tiannetSetDay(tiannetYeartiannetMonth);documentalltiannetMonthHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 月</option>);
}
documentwrite(</select>);
//documentwrite(</div>);
//documentwrite(<div align="center" id="divTiannetTimeText" Author="tiannet">);
documentwrite(<span id="tiannetHourHead" Author="tiannet" style="+s_tiannet_font+display:none;" +
onclick="spanHourCEvent();"> 時</span>);
documentwrite(<select id="selTianHour" style="+s_tiannet_select+display:none;" Author="tiannet" +
onChange="tiannetHour=thisvalue;tiannetWriteHead();documentalltiannetHourHeadstyledisplay=\\; +
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 時</option>);
}
documentwrite(</select>);
documentwrite(<span id="tiannetMinuteHead" Author="tiannet" style="+s_tiannet_font+display:none;" +
onclick="spanMinuteCEvent();">  分</span>);
documentwrite(<select id="selTianMinute" style="+s_tiannet_select+display:none;" Author="tiannet" +
onChange="tiannetMinute=thisvalue;tiannetWriteHead();documentalltiannetMinuteHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 分</option>);
}
documentwrite(</select>);
documentwrite(</div>);
//輸出一條橫線
documentwrite(<div style="+s_tiannet_line+"></div>);
documentwrite(<div align="center" id="divTiannetTurn" style="border:;" Author="tiannet">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="年↑" title="上一年" onClick="tiannetPrevYear();">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="年↓" title="下一年" onClick="tiannetNextYear();"> );
documentwrite(<input type="button" style="+s_tiannet_turn+" value="月↑" title="上一月" onClick="tiannetPrevMonth();">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="月↓" title="下一月" onClick="tiannetNextMonth();">);
documentwrite(</div>);
//輸出一條橫線
documentwrite(<div style="+s_tiannet_line+"></div>);
documentwrite(<table border= cellspacing= cellpadding= bgcolor=white onselectstart="return false">);
documentwrite( <tr style="backgroundcolor:#A;fontsize:pt;color:white;height:px;" Author="tiannet">);
for(var i =;i < weekNamelength;i ++){
//輸出星期
documentwrite(<td width="" align="center" Author="tiannet"> + weekName[i] + </td>);
}
documentwrite( </tr>);
documentwrite(</table>);
//輸出天的選擇
documentwrite(<table border= cellspacing= cellpadding= bgcolor=white onselectstart="return false">);
var n = ;
for (var i=;i<;i++) {
documentwrite ( <tr align=center id="trTiannetDay + i + " >);
for (var j=;j<;j++){
documentwrite(<td align="center" id="tdTiannetDay + n + " +
onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "> </td>);
n ++;
}
documentwrite ( </tr>);
}
documentwrite ( <tr align=center id="trTiannetDay" >);
documentwrite(<td align="center" id="tdTiannetDay" onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "> </td>);
documentwrite(<td align="center" id="tdTiannetDay" onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "> </td>);
documentwrite(<td align="right" colspan=""><a href="javascript:tiannetClear();" style=" + s_tiannet_link + ">清空</a>+
 <a href="javascript:tiannetHideControl();" style=" + s_tiannet_link + ">關閉</a> +
 <a href="javascript:tiannetSetValue(true);" style=" + s_tiannet_link + ">確定</a>  +
</td>);
documentwrite ( </tr>);
documentwrite(</table>);
documentwrite(</div>);
// end 頁面顯示部分 //
// 顯示日期時間的span標簽響應事件 //
//單擊年份span標簽響應
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標簽響應
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);
}
//單擊小時span標簽響應
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標簽響應
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);
}
//根據標簽id隱藏或顯示標簽
function hideElementsById(arrIdbolHide){
var strDisplay = "";
if(bolHide) strDisplay = "none";
for(var i = ;i < arrIdlength;i ++){
var obj = documentgetElementById(arrId[i]);
objstyledisplay = strDisplay;
}
}
// end 顯示日期時間的span標簽響應事件 //
//判斷某年是否為閏年
function isPinYear(year){
var bolRet = false;
if (==year%&&((year%!=)||(year%==))) {
bolRet = true;
}
return bolRet;
}
//得到一個月的天數閏年為
function getMonthCount(yearmonth){
var c=m_aMonHead[month];
if((month==)&&isPinYear(year)) c++;
return c;
}
//重新設置當前的日主要是防止在翻年翻月時當前日大於當月的最大日
function setRealDayCount() {
if( tiannetDay > getMonthCount(tiannetYeartiannetMonth) ) {
//如果當前的日大於當月的最大日則取當月最大日
tiannetDay = getMonthCount(tiannetYeartiannetMonth);
}
}
//在個位數前加零
function addZero(value){
if(value < ){
value = "" + value;
}
return value;
}
//取出空格
function tiannetTrim(str) {
return strreplace(/(^\s*)|(\s*$)/g"");
}
//為select創建一個option
function createOption(objSelectvaluetext){
var option = documentcreateElement("OPTION");
optionvalue = value;
optiontext = text;
objSelectoptionsadd(option);
}
//往前翻 Year
function tiannetPrevYear() {
if(tiannetYear > && tiannetYear <){tiannetYear;}
else{alert("年份超出范圍()!");}
tiannetSetDay(tiannetYeartiannetMonth);
//如果年份小於允許的最小年份則創建對應的option
if( tiannetYear < tiannetYearSt ) {
tiannetYearSt = tiannetYear;
createOption(documentallselTianYeartiannetYeartiannetYear + "年");
}
checkSelect(documentallselTianYeartiannetYear);
tiannetWriteHead();
}
//往後翻 Year
function tiannetNextYear() {
if(tiannetYear > && tiannetYear <){tiannetYear++;}
else{alert("年份超出范圍()!");return;}
tiannetSetDay(tiannetYeartiannetMonth);
//如果年份超過允許的最大年份則創建對應的option
if( tiannetYear > tiannetYearEnd ) {
tiannetYearEnd = tiannetYear;
createOption(documentallselTianYeartiannetYeartiannetYear + "年");
}
checkSelect(documentallselTianYeartiannetYear);
tiannetWriteHead();
}
//選擇今天
function tiannetToday() {
tiannetYear = tiannetDateNowgetFullYear();
tiannetMonth = tiannetDateNowgetMonth()+;
tiannetDay = tiannetDateNowgetDate();
tiannetSetValue(true);
//tiannetSetDay(tiannetYeartiannetMonth);
//selectObject();
}
//往前翻月份
function tiannetPrevMonth() {
if(tiannetMonth>){tiannetMonth}else{tiannetYear;tiannetMonth=;}
tiannetSetDay(tiannetYeartiannetMonth);
checkSelect(documentallselTianMonthtiannetMonth);
tiannetWriteHead();
}
//往後翻月份
function tiannetNextMonth() {
if(tiannetMonth==){tiannetYear++;tiannetMonth=}else{tiannetMonth++}
tiannetSetDay(tiannetYeartiannetMonth);
checkSelect(documentallselTianMonthtiannetMonth);
tiannetWriteHead();
}
//向span標簽中寫入年分等數據
function tiannetWriteHead(){
documentalltiannetYearHeadinnerText = tiannetYear + "年";
documentalltiannetMonthHeadinnerText = tiannetMonth + "月";
if( m_bolShowHour ) documentalltiannetHourHeadinnerText = " "+tiannetHour + "時";
if( m_bolShowMinute ) documentalltiannetMinuteHeadinnerText = tiannetMinute + "分";
tiannetSetValue(false);//給文本框賦值但不隱藏本控件
}
//設置顯示天
function tiannetSetDay(yymm) {
setRealDayCount();//設置當月真實的日
tiannetWriteHead();
var strDateFont = "" strDateFont = "" //處理日期顯示的風格
for (var i = ; i < ; i++){tiannetArrDay[i]=""}; //將顯示框的內容全部清空
var day = ;
var firstday = new Date(yymm)getDay(); //某月第一天的星期幾
for (var i = firstday; day < getMonthCount(yymm)+; i++){
tiannetArrDay[i]=day;day++;
}
//如果用於顯示日的最後一行的第一個單元格的值為空則隱藏整行
//if(tiannetArrDay[] == ""){
// documentalltrTiannetDaystyledisplay = "none";
//} else {
// documentalltrTiannetDaystyledisplay = "";
//}
for (var i = ; i < ; i++){
var da = eval("documentalltdTiannetDay"+i) //書寫新的一個月的日期星期排列
if (tiannetArrDay[i]!="") {
//判斷是否為周末如果是周末則改為紅色字體
if(i % == || (i+) % == ){
strDateFont = "<font color=#f>"
strDateFont = "</font>"
} else {
strDateFont = "";
strDateFont = ""
}
dainnerHTML = strDateFont + tiannetArrDay[i] + strDateFont;
//如果是當前選擇的天則改變顏色
if(tiannetArrDay[i] == tiannetDay ) {
dastylebackgroundColor = "#CCCCCC";
} else {
dastylebackgroundColor = "#EFEFEF";
}
dastylecursor="hand"
} else {
dainnerHTML="";dastylebackgroundColor="";dastylecursor="default"
}
}//end for
tiannetSetValue(false);//給文本框賦值但不隱藏本控件
}//end function tiannetSetDay
//根據option的值選中option
function checkSelect(objSelectselectValue) {
var count = parseInt(objSelectlength);
if( selectValue < && selectValuetoString()length == ) {
selectValue = selectValuesubstring();
}
for(var i = ;i < count;i ++){
if(objSelectoptions[i]value == selectValue){
objSelectselectedIndex = i;
break;
}
}//for
}
//選中年分等下拉框
function selectObject(){
//如果年份小於允許的最小年份則創建對應的option
if( tiannetYear < tiannetYearSt ) {
for( var i = tiannetYear;i < tiannetYearSt;i ++ ){
createOption(documentallselTianYearii + "年");
}
tiannetYearSt = tiannetYear;
}
//如果年份超過允許的最大年份則創建對應的option
if( tiannetYear > tiannetYearEnd ) {
for( var i = tiannetYearEnd+;i <= tiannetYear;i ++ ){
createOption(documentallselTianYearii + "年");
}
tiannetYearEnd = tiannetYear;
}
checkSelect(documentallselTianYeartiannetYear);
checkSelect(documentallselTianMonthtiannetMonth);
if( m_bolShowHour ) checkSelect(documentallselTianHourtiannetHour);
if( m_bolShowMinute ) checkSelect(documentallselTianMinutetiannetMinute);
}
//給接受日期時間的控件賦值
//參數bolHideControl 是否隱藏控件
function tiannetSetValue(bolHideControl){
var value = "";
if( !tiannetDay || tiannetDay == "" ){
tiannetOutObjectvalue = value;
return;
}
var mm = tiannetMonth;
var day = tiannetDay;
if( mm < && mmtoString()length == ) mm = "" + mm;
if( day < && daytoString()length == ) day = "" + day;
value = tiannetYear + tiannetDateSplit + mm + tiannetDateSplit + day;
if( m_bolShowHour ){
var hour = tiannetHour;
if( hour < && hourtoString()length == ) hour = "" + hour;
value += tiannetDateTimeSplit + hour;
}
if( m_bolShowMinute ){
var minute = tiannetMinute;
if( minute < && minutetoString()length == ) minute = "" + minute;
value += tiannetTimeSplit + minute;
}
tiannetOutObjectvalue = value;
//documentalldivTiannetDatestyledisplay = "none";
if( bolHideControl ) {
tiannetHideControl();
}
}
//是否顯示時間
function showTime(){
if( !m_bolShowHour && m_bolShowMinute){
alert("如果要選擇分鐘則必須可以選擇小時!");
return;
}
hideElementsById(new Array("tiannetHourHead""selTianHour""tiannetMinuteHead""selTianMinute")true);
if( m_bolShowHour ){
//顯示小時
hideElementsById(new Array("tiannetHourHead")false);
}
if( m_bolShowMinute ){
//顯示分鐘
hideElementsById(new Array("tiannetMinuteHead")false);
}
}
//彈出顯示日歷選擇控件以讓用戶選擇
function tiannetPopCalendar(){
//隱藏下拉框顯示相對應的head
hideElementsById(new Array("selTianYear""selTianMonth""selTianHour""selTianMinute")true);
hideElementsById(new Array("tiannetYearHead""tiannetMonthHead""tiannetHourHead""tiannetMinuteHead")false);
tiannetSetDay(tiannetYeartiannetMonth);
tiannetWriteHead();
showTime();
var dads = documentalldivTiannetDatestyle;
var iX iY;
var h = documentalldivTiannetDateoffsetHeight;
var w = documentalldivTiannetDateoffsetWidth;
//計算left
if (windoweventx + h > documentbodyoffsetWidth )
iX = windoweventx h ;
else
iX = windoweventx + ;
if (iX <)
iX=;
//計算top
iY = windoweventy;
if (windoweventy + w > documentbodyoffsetHeight )
iY = documentbodyscrollTop + documentbodyoffsetHeight w ;
else
iY = documentbodyscrollTop +windoweventy + ;
if (iY <)
iY=;
dadsleft = iX;
dadstop = iY;
tiannetShowControl();
selectObject();
}
//隱藏日歷控件(同時顯示被強制隱藏的標簽)
function tiannetHideControl(){
documentalldivTiannetDatestyledisplay = "none";
tiannetShowObject();
arrTiannetHide = new Array();//將被隱藏的標簽對象清空
}
//顯示日歷控件(同時隱藏會遮擋的標簽)
function tiannetShowControl(){
documentalldivTiannetDatestyledisplay = "";
tiannetHideObject("SELECT");
tiannetHideObject("OBJECT");
}
//根據標簽名稱隱藏標簽如會遮住控件的selectobject
function tiannetHideObject(strTagName) {
x = documentalldivTiannetDateoffsetLeft;
y = documentalldivTiannetDateoffsetTop;
h = documentalldivTiannetDateoffsetHeight;
w = documentalldivTiannetDateoffsetWidth;
for (var i = ; i < documentalltags(strTagName)length; i++)
{
var obj = documentalltags(strTagName)[i];
if (! obj || ! objoffsetParent)
continue;
// 獲取元素對於BODY標記的相對坐標
var objLeft = objoffsetLeft;
var objTop = objoffsetTop;
var objHeight = objoffsetHeight;
var objWidth = objoffsetWidth;
var objParent = objoffsetParent;
while (objParenttagNametoUpperCase() != "BODY"){
objLeft += objParentoffsetLeft;
objTop += objParentoffsetTop;
objParent = objParentoffsetParent;
}
//alert("控件左端:" + x + "select左端" + (objLeft + objWidth) + "控件底部:" + (y+h) + "select高:" + objTop);
var bolHide = true;
if( objstyledisplay == "none" || objstylevisibility == "hidden" || objgetAttribute("Author") == "tiannet" ){
//如果標簽本身就是隱藏的則不需要再隱藏如果是控件中的下拉框也不用隱藏
bolHide = false;
}
if( ( (objLeft + objWidth) > x && (y + h + ) > objTop && (objTop+objHeight) > y && objLeft < (x+w) ) && bolHide ){
//arrTiannetHidepush(obj);//記錄被隱藏的標簽對象
arrTiannetHide[arrTiannetHidelength] = obj;
objstylevisibility = "hidden";
}
}
}
//顯示被隱藏的標簽
function tiannetShowObject(){
for(var i = ;i < arrTiannetHidelength;i ++){
//alert(arrTiannetHide[i]);
arrTiannetHide[i]stylevisibility = "";
}
}
//初始化日期
function tiannetInitDate(strDate){
var arr = strDatesplit(tiannetDateSplit);
tiannetYear = arr[];
tiannetMonth = arr[];
tiannetDay = arr[];
}
//清空
function tiannetClear(){
tiannetOutObjectvalue = "";
tiannetHideControl();
}
//任意點擊時關閉該控件
function documentonclick(){
with(windoweventsrcElement){
if (tagName != "INPUT" && getAttribute("Author") != "tiannet")
tiannetHideControl();
}
}
//按ESC鍵關閉該控件
function documentonkeypress(){
if( eventkeyCode == ){
tiannetHideControl();
}
}

  
Calendarhtml:

復制代碼 代碼如下:

  
<!DOCTYPE HTML PUBLIC "//WC//DTD HTML Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio NET ">
<meta name="ProgId" content="VisualStudioHTML">
<meta name="Originator" content="Microsoft Visual Studio NET ">
<script src="/Calendarjs"></script>
</head>
<body>
()只選擇日期 <input type="text" name="date" readOnly onClick="setDay(this);"><br/>
()選擇日期和小時 <input type="text" name="dateh" readOnly onClick="setDayH(this);"><br/>
()選擇日期和小時及分鐘 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20261.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.