百分求一个日历的javascript代码
劳烦提供一个日历的javascript代码
效果是点击DIV中的一个TEXT,出现一个日历,可以选择日期,选择完后TEXT中就显示选中的日期
[解决办法]
function selecttimefun(){
var timestring = showModalDialog( "/huadu_master_admins/seledatetime.jsp ", " ", "dialogLeft: "+(event.screenX-80)+ ";dialogTop: "+(event.screenY-80)+ ";dialogWidth:165px; dialogHeight:165px; edge:raised;help:off;status:off;scroll:off ");
if(timestring!= " ")
{
document.form3.times_exps.value = timestring;
document.getElementById( "times ").innerHTML=timestring;
}
}
-------------------------------------------------
<%@ page language= "java " contentType= "text/html; charset=utf-8 "
pageEncoding= "utf-8 "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<title> 选择时间 </title>
<style>
.input1{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;}
input{font-family: "宋体 "; font-size:9pt;height:18px;line-height: 12pt;}
</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> </tr> <tr> <td colspan=7 bgcolor=black> <spacer height=1 type=block> </td> </tr> "
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= '#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 ' class=input1 value= ' "+n.toString()+ " ' style= 'width:20 ' onclick= 'setvalue( "+n.toString()+ ") '> "
}
function setvalue(n)
{
window.returnValue=document.all.years.value+ "- "+document.all.months.value+ "- "+n
document.all.days.value=n.toString()
window.close();
}
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 " bgcolor= "#EFEBDE " oncontextmenu= "return false; ">
<div align= "center ">
<table border=0 id= "datesbox " cellspacing=0 cellpadding=2 width= "151 " height= "23 ">
<tr>
<td rowspan=2 align= "center " width= "40 ">
<input type= "hidden " size= "2 " name= "days " value= " ">
<input name= "years " size=4 value= "0 " onKeyUp= "checkinput();changeit(eval(days.value),eval(months.value),eval(years.value)) " onBlur= "checkinput() " maxlength=4>
</td>
<td width= "20 " style= "padding-right:1px " height= "11 " valign= "bottom ">
<div name= "yearup " style= "cursor:hand; " onClick= "yearadd(1) "> <img alt= "年份向后 " src= "/images/up.gif " width= "9 " height= "6 "> </div>
</td>
<td rowspan= "2 " width= "79 ">
<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>
</tr>
<tr>
<td width= "20 " valign= "top ">
<div name= "yeardown " style= "cursor:hand; " onClick= "yearadd(-1) " valign= "top "> <img alt= "年份向前 " src= "/images/down.gif " width= "9 " height= "6 "> </div>
</td>
</tr>
</table>
<div id=daysin style= "padding-top:4px "> </div>
</div>
</body>
<script language= "javascript ">
//显示时间
function initdates()
{
var d=new Date()
days.value=d.getDate()
months.value=d.getMonth()+1
years.value=d.getYear()
window.returnValue = " "
//window.returnValue=d.getYear().toString()+ "- "+(d.getMonth()+1).toString()+ "- "+(d.getDate()).toString()
daysin.innerHTML=displaydates(d.getDate()-1,d.getMonth(),d.getYear(),true)
}
initdates();
</script>
</html>
[解决办法]
我的csdn博客中有,地址:http://blog.csdn.net/superjava_2006/archive/2007/07/15/1691790.aspx
[解决办法]
搜索梅花雪日历控件~