自己的萬年歷和年月歷,可以跨frame
需IE5.5 + 方可使用
========data.htm========
<script language="javascript" src="getYM.js"></script>
<script language="javascript" src="getCale.js"></script>
<input type="text" id="date">
<input type="button" value="click here" onclick="getYM(document.all('date'))">
<input type="text" id="date1">
<input type="button" value="click here" onclick="getDATE(document.all('date1'))">
<br/>adgagagafhafhafdgadfgafg<select><option>asdag</option></select>===========getYM.js==========
/*name:獲取年月控件
author:liuzxit
design-date:2002/12/19
note:在IE5.5下測試通過
*/var tarObject
var d=new Date()
sYear=d.getFullYear()
sMonth=d.getMonth() + 1popup = window.createPopup()
popBody = popup.document.body
popBody.style.border="outset 1pt #cccccc"
popBody.style.fontSize = "9pt"
popBody.style.backgroundColor= "#c6c6c6"
popBody.style.cursor="hand"var strPop='<table id="yMonth" author="liuzxit" border="1" bordercolorlight="#0053a6" bordercolordark="#ffffff" cellpadding="1" cellspacing="0" style="font-size:9pt;">'
strPop+='<th width="28" bgcolor="#ff0000" onclick="parent.yearRoll(-4)" style="color:#00ffff;"><<'
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear - 2)
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear - 1)
strPop+='<th width="28" bgcolor="#ffffff" style="color:#ff0000" onclick="parent.selectClicked(this)">'+sYear
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear + 1)
strPop+='<th width="28" bgcolor="#ff0000" onclick="parent.yearRoll(4)" style="color:#00ffff;">>></th>'
strPop+='<tr align="center"><td style="border:solid 1pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">1'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">2'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">3'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">4'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">5'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">6</td></tr>'
strPop+='<tr align="center"><td style="border:solid 1pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">7'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">8'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">9'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">10'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">11'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">12</td></tr>'
strPop+='<tr align="center" bgcolor="#848484" style="color:#ffffff"><td colspan=3 onclick="parent.selectClicked(this)">本年月'
strPop+='<td colspan=3 onclick="parent.hidePop();">關閉</td></tr>'
strPop+='</table>'
popBody.innerHTML=strPopfunction tdMove(e){e.style.border="outset 2pt #ffffff"}
function tdOut(e){e.style.border="solid 2pt #c6c6c6"}
function yearRoll(n){
var e=popup.document.all('yMonth')
e.cells[1].innerText = parseInt(e.cells[1].innerText) + parseInt(n)
e.cells[2].innerText = parseInt(e.cells[2].innerText) + parseInt(n)
e.cells[3].innerText = parseInt(e.cells[3].innerText) + parseInt(n)
e.cells[4].innerText = parseInt(e.cells[4].innerText) + parseInt(n)
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(tarObject.value)
tarObject.value=(parseInt(r[1])+n)+'/'+r[3]
}function selectClicked(e){
var p=e.parentElement
switch(p.rowIndex){
case 0:for(var i=1;i<5;i++){
p.cells[i].style.backgroundColor='#000000';
p.cells[i].style.color='#ffffff';
}
e.style.backgroundColor='#ffffff';
e.style.color='#ff0000';
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,e.innerText+'/$3');
break;
case 3:tarObject.value=sYear+'/'+sMonth;
popup.hide();
break;
default:
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,'$1/'+e.innerText);
e.style.border="solid 1pt #c6c6c6"
popup.hide();
break;
}
}function hidePop(){popup.hide()}
function getYM(s){
tarObject=s
if (s.value=='')s.value=sYear+'/'+sMonth
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(s.value)
if (r==null){s.value=sYear+'/'+sMonth;
r=reg.exec(s.value)}
var e=popup.document.all('yMonth').rows[0]
for (var i=1;i<5;i++){
if (e.cells[i].style.color=='#ff0000'){
s.value=e.cells[i].innerText+'/'+r[3]
yearRoll(r[1] - e.cells[i].innerText);
break;
}
}
var e=event.srcElement
popup.show(-70,e.clientHeight+5,196,84,e)
}
需IE5.5 + 方可使用
========data.htm========
<script language="javascript" src="getYM.js"></script>
<script language="javascript" src="getCale.js"></script>
<input type="text" id="date">
<input type="button" value="click here" onclick="getYM(document.all('date'))">
<input type="text" id="date1">
<input type="button" value="click here" onclick="getDATE(document.all('date1'))">
<br/>adgagagafhafhafdgadfgafg<select><option>asdag</option></select>===========getYM.js==========
/*name:獲取年月控件
author:liuzxit
design-date:2002/12/19
note:在IE5.5下測試通過
*/var tarObject
var d=new Date()
sYear=d.getFullYear()
sMonth=d.getMonth() + 1popup = window.createPopup()
popBody = popup.document.body
popBody.style.border="outset 1pt #cccccc"
popBody.style.fontSize = "9pt"
popBody.style.backgroundColor= "#c6c6c6"
popBody.style.cursor="hand"var strPop='<table id="yMonth" author="liuzxit" border="1" bordercolorlight="#0053a6" bordercolordark="#ffffff" cellpadding="1" cellspacing="0" style="font-size:9pt;">'
strPop+='<th width="28" bgcolor="#ff0000" onclick="parent.yearRoll(-4)" style="color:#00ffff;"><<'
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear - 2)
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear - 1)
strPop+='<th width="28" bgcolor="#ffffff" style="color:#ff0000" onclick="parent.selectClicked(this)">'+sYear
strPop+='<th width="28" bgcolor="#000000" style="color:#ffffff" onclick="parent.selectClicked(this)">'+(sYear + 1)
strPop+='<th width="28" bgcolor="#ff0000" onclick="parent.yearRoll(4)" style="color:#00ffff;">>></th>'
strPop+='<tr align="center"><td style="border:solid 1pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">1'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">2'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">3'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">4'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">5'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">6</td></tr>'
strPop+='<tr align="center"><td style="border:solid 1pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">7'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">8'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">9'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">10'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">11'
strPop+='<td style="border:solid 2pt #c6c6c6;" onmouseover="parent.tdMove(this)" onmouseout="parent.tdOut(this)" onclick="parent.selectClicked(this)">12</td></tr>'
strPop+='<tr align="center" bgcolor="#848484" style="color:#ffffff"><td colspan=3 onclick="parent.selectClicked(this)">本年月'
strPop+='<td colspan=3 onclick="parent.hidePop();">關閉</td></tr>'
strPop+='</table>'
popBody.innerHTML=strPopfunction tdMove(e){e.style.border="outset 2pt #ffffff"}
function tdOut(e){e.style.border="solid 2pt #c6c6c6"}
function yearRoll(n){
var e=popup.document.all('yMonth')
e.cells[1].innerText = parseInt(e.cells[1].innerText) + parseInt(n)
e.cells[2].innerText = parseInt(e.cells[2].innerText) + parseInt(n)
e.cells[3].innerText = parseInt(e.cells[3].innerText) + parseInt(n)
e.cells[4].innerText = parseInt(e.cells[4].innerText) + parseInt(n)
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(tarObject.value)
tarObject.value=(parseInt(r[1])+n)+'/'+r[3]
}function selectClicked(e){
var p=e.parentElement
switch(p.rowIndex){
case 0:for(var i=1;i<5;i++){
p.cells[i].style.backgroundColor='#000000';
p.cells[i].style.color='#ffffff';
}
e.style.backgroundColor='#ffffff';
e.style.color='#ff0000';
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,e.innerText+'/$3');
break;
case 3:tarObject.value=sYear+'/'+sMonth;
popup.hide();
break;
default:
tarObject.value=tarObject.value.replace(/(\d{4})(\/)(\d{1,2})/,'$1/'+e.innerText);
e.style.border="solid 1pt #c6c6c6"
popup.hide();
break;
}
}function hidePop(){popup.hide()}
function getYM(s){
tarObject=s
if (s.value=='')s.value=sYear+'/'+sMonth
var reg=/(\d{4})(\/)(\d{1,2})/
var r=reg.exec(s.value)
if (r==null){s.value=sYear+'/'+sMonth;
r=reg.exec(s.value)}
var e=popup.document.all('yMonth').rows[0]
for (var i=1;i<5;i++){
if (e.cells[i].style.color=='#ff0000'){
s.value=e.cells[i].innerText+'/'+r[3]
yearRoll(r[1] - e.cells[i].innerText);
break;
}
}
var e=event.srcElement
popup.show(-70,e.clientHeight+5,196,84,e)
}
/*name:萬年歷控件
author:liuzxit
design-date:2002/12/19
note:在IE5.5下測試通過
*/function caleTDMove(e){e.style.borderColor="#ffffff #333333 #333333 #ffffff"}
function caleTDOut(e){e.style.border="solid 1pt #c6c6c6"}
function hideCale(){popCale.hide()}function yearChange(){ //重寫年份的<SELECT>
var e=popCale.document.all('yearSel')
e.options.length=0
for (i=nYear-4;i<parseInt(nYear)+5;i++){
e.options.length++
e.options[e.options.length - 1].value=i
e.options[e.options.length - 1].text=i
}
e.selectedIndex=4
}function CaleClick(e){ //選定某一天時
if(isNaN(parseInt(e.innerText))){ //如果是點擊"今天"而觸發
var d=new Date()
tarObject.value=d.getFullYear()+'/'+(d.getMonth()+1)+'/'+d.getDate()
e.style.borderColor="#848484"
}
else{tarObject.value=nYear+'/'+(parseInt(nMonth)+1)+'/'+e.innerText
e.style.borderColor="#c6c6c6"
}
popCale.hide()
}function changeYM(e,n){ //改變年份或月份﹐或點>>和<<時觸發
if (e.tagName=='SELECT'){
if(e.value.length==4){nYear=e.value;yearChange()}
else{nMonth=e.value}
}
else{nMonth=parseInt(nMonth)+n
switch(nMonth){
case 12:nYear++;nMonth=0;
yearChange()
popCale.document.all('monthSel').selectedIndex=0;break;
case -1:nYear--;nMonth=11;
yearChange()
popCale.document.all('monthSel').selectedIndex=11;break;
default:popCale.document.all('monthSel').selectedIndex=nMonth;break;
}
}
rewriteCale()
}function rewriteCale(){ //重寫日歷
var newTb,newTR,newTD
newTb=popCale.document.all('LiuzxCale').tBodies[0]
for (i=0;i<=newTb.rows.length;i++)newTb.deleteRow(2)
qtyDay=(new Date(nYear,parseInt(nMonth)+1,1) - new Date(nYear,nMonth,1))/24/3600/1000
fDay=1-(new Date(nYear,nMonth,1).getDay())
for (i=0;i<42;i++){
if (i % 7==0)newTR=newTb.insertRow(newTb.rows.length - 2)
newTD=newTR.insertCell()
if (fDay>0 && fDay<=qtyDay)newTD.innerText=fDay
newTD.style.border="solid 1pt #c6c6c6"
newTD.align='center'
newTD.onmouseover=Function("parent.caleTDMove(this)")
newTD.onmouseout=Function("parent.caleTDOut(this)")
newTD.onclick=Function("parent.CaleClick(this)")
fDay++
}
}function isDate(str){ //判斷日期是否是合法的
var reg = /^(\d{4})(-|\/)(0?[1-9]|1[0-2])(-|\/)(0?[1-9]|[12][0-9]|3[01])$/g;
var r = reg.exec(str);
if(r==null)return false;
var d = new Date(r[1], r[3]-1,r[5]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
var reg=/(\/|-)(0*)( *)([1-9])/g
var t=str.replace(reg,'$1$4')
if (newStr==t)return true;
return false;
}function getDATE(s){ //設定那個控件加入萬年歷
tarObject=s
if ((s.value!='')&&(isDate(s.value))){ //如果控件原來有日期并且是合法的
var reg=/(\d{4})(\/)(\d{1,2})(\/)(\d{1,2})/
var r=reg.exec(s.value);
nYear=r[1];nMonth=r[3] - 1;
}
else{
var d=new Date()
nYear=d.getFullYear();nMonth=d.getMonth();
}
var e=event.srcElement
popCale.show(-70,e.clientHeight+5,185,172,e)
popCale.document.all('monthSel').selectedIndex=nMonth
yearChange()
rewriteCale()
}//創建萬年歷
popCale = window.createPopup()
CaleBody = popCale.document.body
CaleBody.style.border="outset 1pt #cccccc"
CaleBody.style.fontSize = "9pt"
CaleBody.style.backgroundColor= "#c6c6c6"
CaleBody.style.cursor="hand"var d=new Date()
var nYear=d.getFullYear()
var nMonth=d.getMonth()
var arMonth=new Array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月')
var qtyDay=(new Date(nYear,parseInt(nMonth)+1,1) - new Date(nYear,nMonth,1))/24/3600/1000
var strCale='<table bgcolor="#c6c6c6" id="LiuzxCale" author="liuzxit" border="1"'
strCale+=' bordercolorlight="#0053a6" bordercolordark="#ffffff" cellpadding="1"'
strCale+=' cellspacing="0" style="font-size:9pt;height:170;cursor:hand;">'
strCale+='<th bgcolor="#848484" style="color:#00ffff;border:solid 1pt #848484"'
strCale+=' onclick="parent.changeYM(this,-1)"><<'
strCale+='<th colspan=2 style="border:solid 1pt #c6c6c6">'
strCale+='<select id="yearSel" onchange="parent.changeYM(this)" style="font:9pt;"></select>'
strCale+='<th colspan=3 style="border:solid 1pt #c6c6c6">'
strCale+='<select id="monthSel" onchange="parent.changeYM(this)" style="font:9pt;">'
for (i=0;i<12;i++){
strCale+='<option value='+i+(i==nMonth+1?' selected':'')+'>'+arMonth[i]+'</option>'
}
strCale+='</select><th bgcolor="#848484" style="color:#00ffff;border:solid 1pt #848484"'
strCale+=' onclick="parent.changeYM(this,1)">>></th>'
strCale+='<tr align=center style="color:#ffffff" bgcolor="#000000">'
strCale+='<td width=22 bgcolor="#ff0000">日'
strCale+='<td width=22>一<td width=22>二<td width=22>三<td width=22>四<td width=22>五'
strCale+='<td width=22 bgcolor="#ff0000">六</td></tr>'
var fDay=1-(new Date(nYear,nMonth,1).getDay())
for (i=0;i<42;i++){
if (i % 7==0)strCale+='<tr align=center>'
strCale+='<td style="border:solid 1pt #c6c6c6" onmouseover="parent.caleTDMove(this)"'
strCale+=' onmouseout="parent.caleTDOut(this)" onclick="parent.CaleClick(this)">'
strCale+=(fDay>0&&fDay<=qtyDay?fDay:'')+'</td>'
fDay++
}
strCale+='</tr>'
strCale+='<tr align=center bgcolor="#848484">'
strCale+='<td style="border:1pt solid #848484"> '
strCale+='<td colspan=2 style="border:1pt solid #848484" onmouseover="parent.caleTDMove(this)"'
strCale+=' onmouseout="this.style.borderColor=\'#848484\'"'
strCale+=' onclick="parent.CaleClick(this)">今天'
strCale+='<td style="border:1pt solid #848484"> '
strCale+='<td colspan=2 style="border:1pt solid #848484"'
strCale+=' onclick="this.style.borderColor=\'#848484\';parent.hideCale();"'
strCale+=' onmouseover="parent.caleTDMove(this)"'
strCale+=' onmouseout="this.style.borderColor=\'#848484\'">關閉'
strCale+='<td style="border:1pt solid #848484"> </td><tr>'
strCale+='</table>'
CaleBody.innerHTML=strCale
yearChange()
http://hazeline.vip.sina.com/calendar.htm