送各位一个节日礼物--日期选择器(和ACTIVEX一样酷!原创)
发表于:2007-06-30来源:作者:点击数:
标签:
-------------date.html html style input{font-family: 宋体; font-size:9pt;height:15px;border:0px black solid;background:#f0f0f0;cursor:hand;background:none} td {font-family: 宋体; font-size:9pt;} select{font-family: 宋体; font-size:9pt;} .in
-------------date.html
<html>
<style>
input{font-family: "宋体"; font-size:9pt;height:15px;border:0px black solid;background:#f0f0f0;cursor:hand;background:none}
td{font-family: "宋体"; font-size:9pt;}
select{font-family: "宋体"; font-size:9pt;}
.input1{font-family: "宋体"; font-size:9pt;height:18px;line-height: 12pt;border:1px black solid;background:#e0e0e0}
</style>
<script language="
javascript">
function checkinput()
{
while (isNaN(document.all.years.value) || (document.all.years.value==" "))
{
document.all.years.value=years.value.substring(0,years.value.length-1)
}
}
function numberofdays(month,year)
{
var numdays=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
n=numdays[month]
if (month==1&&year%4==0) ++n
return n
}
function displaydates(day,month,year,shade){
d=new Date(year,month,1)
var startday=d.getDay()
var numdays=numberofdays(month,year)
var numrows=Math.ceil((numdays+startday)/7)
var tmps=""
if((numdays+startday)%7>1) ++numrows
var currentdate=0
tmps="<table border=0 cellpadding=0 cellspacing=0><tr><td align=@#center@#>日</td><td align=@#center@#>一</td><td align=@#center@#>二</td><td align=@#center@#>三</td><td align=@#center@#>四</td><td align=@#center@#>五</td><td align=@#center@#>六</td></r>"
for (var i=0;i<numrows;++i)
{
tmps=tmps+"<tr>"
for(var j=0;j<7;++j){
if (shade&&day==currentdate&¤tdate<numdays&&i*7+j>=startday)
tmps=tmps+"<td bgcolor=@##
clearcase/" target="_blank" >cccccc@# style=@#border:1px solid #909090@#>"
else tmps=tmps+"<td>"
if(currentdate>=numdays) tmps=tmps+" "
else if(currentdate>0){
++currentdate
tmps=tmps+writedate(currentdate)
} else if(i*7+j>=startday){
++currentdate
tmps=tmps+writedate(currentdate)
}else tmps=tmps+" "
tmps=tmps+"</td>"
}
tmps=tmps+"</tr>"
}
tmps=tmps+"</table>"
return tmps
}
function writedate(n){
return "<input type=@#button@# value=@#"+n.toString()+"@# style=@#width:20@# onclick=@#setvalue("+n.toString()+")@#>"
}
function setvalue(n)
{
document.all.dates.value=document.all.years.value+"-"+document.all.months.value+"-"+n
document.all.days.value=n.toString()
datesbox.style.visibility="hidden"
}
function showdates()
{
if ((event.x+150)>document.body.offsetWidth )
datesbox.style.left=event.x+document.body.scrollLeft-150
else
datesbox.style.left=event.x+document.body.scrollLeft
if ((event.y+165)>document.body.offsetHeight )
datesbox.style.top=event.y+document.body.scrollTop-165
else
datesbox.style.top=event.y+document.body.scrollTop
if (datesbox.style.visibility=="visible")
datesbox.style.visibility="hidden"
else
datesbox.style.visibility="visible"
yearadd(0)
}
function showdates2()
{
if (datesbox.style.visibility=="visible")
datesbox.style.visibility="hidden"
}
function changeit(d,m,y)
{
daysin.innerHTML=displaydates(d,m-1,y,true)
}
function yearadd(n)
{
years.value=(eval(years.value)+n).toString()
changeit(eval(days.value)-1,eval(months.value),eval(years.value))
}
</script>
<body style="font-size:9pt">
<DIV id="datesbox" STYLE="border:1px solid #c0c0c0;padding:5px 5px 5px 5px;background:#f0f0f0;HEIGHT:165px; LEFT: 50px; POSITION: absolute; TOP: 31px; VISIBILITY: hidden; WIDTH: 150px" ondblclick=@#showdates2()@#>
<table border=0 cellspacing=0 cellpadding=0><tr><td rowspan=2 align="center"> <input type="hidden" size="2" name="days" value=""><select name="months" onchange="changeit(eval(days.value)-1,eval(months.value),eval(years.value))" style="length:320"><option value=1 selected
>一月</option>
<option value=2>二月</option>
<option value=3>三月</option>
<option value=4>四月</option>
<option value=5>五月</option>
<option value=6>六月</option>
<option value=7>七月</option>
<option value=8>八月</option>
<option value=9>九月</option>
<option value=10>十月</option>
<option value=11>十一月</option>
<option value=12>十二月</option>
</select></td><td rowspan=2 style="padding-right:1px"> <input name="years" size=4 value="0" class="input1" onkeyup="checkinput();changeit(eval(days.value),eval(months.value),eval(years.value))" onblur="checkinput()" maxlength=4></td><td><input type="button" name="yea
rup" class="input1" onclick="yearadd(1)" style="height:9px;width:15px"></td>
</tr>
<tr><td><input type="button" name="yeardown" class="input1" value="v" style="height:9px;width:15px" onclick="yearadd(-1)"></td>
</tr>
</table><hr size=1 width="100%" color="#c0c0c0">
<div id=daysin></div>
</DIV>
<form action="getvalue.asp" method="post">
日期:<input name="dates" class="input1" readonly style="font-color:black"> <input type="button" class="input1" name="btndate" value="..." onclick="showdates()">
<input type="submit" value="submit" class="input1">
</form>
</body>
<script language="javascript">
function initdates()
{
var d=new Date()
days.value=d.getDate()
months.value=d.getMonth()+1
years.value=d.getYear()
document.all.dates.value=d.getYear().toString()+"-"+(d.getMonth()+1).toString()+"-"+(d.getDate()).toString()
daysin.innerHTML=displaydates(d.getDate()-1,d.getMonth(),d.getYear(),true)
}
initdates()
</script>
</html>
----------getvalue.asp
<%=Request.Form("dates")
%>
原文转自:http://www.ltesting.net