打印本文 打印本文 关闭窗口 关闭窗口
一个在时间选择上很有用的代码
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1895  更新时间:2009/4/23 11:27:08  文章录入:mintao  责任编辑:mintao
p; fSetYearMon(giYear, giMonth);
  var point = fGetXY(popCtrl);
  with (VicPopCal.style) {
   left = point.x+10;   //弹出窗口的坐标
 top  = point.y+popCtrl.offsetHeight+15;
 width = VicPopCal.offsetWidth;
 width = 180; //
 height = VicPopCal.offsetHeight;
 height = 180;
 fToggleTags(point);  
 visibility = 'visible';
  }
}

// Added by Han Chen
function fInitialDate(strDate){
 if( strDate == null || strDate.length != 10 )
  return false;

 var sYear  = strDate.substring(0,4);
 var sMonth = strDate.substring(5,7);
 var sDay   = strDate.substring(8,10);

 if( sMonth.charAt(0) == '0' ) { sMonth = sMonth.substring(1,2); }
 if( sDay.charAt(0)   == '0' ) { sDay   = sDay.substring(1,2);   }

 var nYear  = parseInt(sYear );
 var nMonth = parseInt(sMonth);
 var nDay   = parseInt(sDay  );
 
 if ( isNaN(nYear ) ) return false;
 if ( isNaN(nMonth) ) return false;
 if ( isNaN(nDay  ) ) return false;

 var arrMon = new Array(12);
 arrMon[ 0] = 31; arrMon[ 1] = nYear % 4 == 0 ? 29:28;
 arrMon[ 2] = 31; arrMon[ 3] = 30;
 arrMon[ 4] = 31; arrMon[ 5] = 30;
 arrMon[ 6] = 31; arrMon[ 7] = 31;
 arrMon[ 8] = 30; arrMon[ 9] = 31;
 arrMon[10] = 30; arrMon[11] = 31;

 if ( nYear  < 1900 || nYear > 2100 )   return false;
 if ( nMonth < 1 || nMonth > 12 )    return false;
 if ( nDay < 1 || nDay > arrMon[nMonth - 1] ) return false;

 giYear  = nYear;
 giMonth = nMonth;
 giDay   = nDay;
 return true;
}

var gMonths = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");

with (document) {
write("<Div id='VicPopCal' style='POSITION:absolute;VISIBILITY:hidden;border:2px ridge;z-index:100;'>");
write("<table border='0' bgcolor='#cccccc'>");
write("<TR>");
write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:bold' onClick='fPrevMonth()'>");
write("&nbsp;<SELECT name='tbSelYear' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for(i=1950;i<2030;i++)
 write("<OPTION value='"+i+"'>"+i+" 年</OPTION>");
write("</SELECT>");
write("&nbsp;<select name='tbSelMonth' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for (i=0; i<12; i++)
 write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
write("</SELECT>");


write("&nbsp;<input type='button' name='PrevMonth' value='>' style='height:20;width:20' onclick='fNextMonth()'>");
write("</td>");
write("</TR><TR>");
write("<td align='center'>");
write("<DIV style='background-color:teal'><table width='100%' border='0'>");
fDrawCal(giYear, giMonth, 0, '0');
write("</table></DIV>");
write("</td>");
write("</TR><TR><TD align='center'>");


//
write("&nbsp;<select name='tbSelHour' onChange='fTime(tbSelHour,tbSelSec,tbSelMin)' Victor='Won'>");
for(i=0;i<24;i++)
 {
 if(i<10)
 {
  write("<OPTION value='0"+i+"'>"+i+"时</OPTION>");
 }
 else
 {
  write("<OPTION value='"+i+"'>"+i+"时</OPTION>");
 }
 }
write("</SELECT>");

write("&nbsp;<select name='tbSelSec' onChange='fTime(tbSelHour,tbSelSec,tbSelMin)' Victor='Won'>");
for(i=0;i<60;i++)
 if(i<10)
 {
  write("<OPTION value='0"+i+"'>"+i+"分</OPTION>");
 }
 else
 {
  write("<OPTION value='"+i+"'>"+i+"分</OPTION>");
 }
write("</SELECT>");

write("&nbsp;<select name='tbSelMin' onChange='fTime(tbSelHour,tbSelSec,tbSelMin)' Victor='Won'>");
for(i=0;i<60;i++)
 if(i<10)
 {
  write("<OPTION value='0"+i+"'>"+i+"秒</OPTION>");
 }
 else
 {
  write("<OPTION value='"+i+"'>"+i+"秒</OPTION>");
 }
write("</SELECT>");
//


write("<TABLE width='100%'><TR><TD align='center'>");
write("<font size='2'  onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=0'>&nbsp;清空</font>"); 
//B style='cursor:hand'被替换为font size='2'
write("</td><td algin='center'>");
write("<font size='2'  onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=0'>今天: "+giYear+"-"+giMonth+"-"+giDay+"</font>");
//B style='cursor:hand'被替换为font size='2'
write("</td></tr></table>");
write("</TD></TR>");
write("</TABLE></Div>");
}


HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
</head>

<body>

<body bgcolor="#D6D3CE">

<script language="javascript" src="time.js">  //调用JS代码
</script>
<div align="center">
  <center>
  <table width="248" border="0">
    <tr>
      <td nowrap width="599"><span class="style1">选择时间</span>:<input class="input" onclick="fPopCalendar(regdate,regdate);return false" type="text" name="regdate" size="30"></td>
    </tr>
  </table>
  </center>
</div>

</body>

</body>
</html>

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口