Javascript语言用3个列表框(select)实现的年、月、日三级联动
2009-02-14 18:23
786 查看
以下是代码:
<HTML>
<HEAD>
<TITLE>日历</TITLE>
</HEAD>
<BODY onload="load()">
<SCRIPT LANGUAGE="JavaScript">
function TGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function TUpdateCal(iYear, iMonth) {
var dDate=new Date();
daysInMonth = TGetDaysInMonth(iMonth, iYear);
while(document.all.tbSelDay.childNodes.length>0)
{
document.all.tbSelDay.removeChild(document.all.tbSelDay.childNodes[0]);
}
for (d = 1; d <= parseInt(daysInMonth); d++) {
option=document.createElement("option");
option.value=d;
option.appendChild(document.createTextNode(d));
document.all.tbSelDay.appendChild(option);
if(d==dDate.getDate())
{
option.selected=true;
}
}
}
function load()
{
<!--出始化年-->
var dDate = new Date();
var dCurYear = dDate.getFullYear();
for(var i=dCurYear-10;i<dCurYear+5;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelYear.appendChild(option);
if(i==dCurYear)
{
option.selected=true;
}
}
<!--出始化月-->
for(var i=1;i<=12;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelMonth.appendChild(option);
if(i==(dDate.getMonth()+1))
{
option.selected=true;
}
}
}
</script>
<form name="frmCalendarSample" method="post" action="">
年:
<select name="tbSelYear" onchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
月:
<select name="tbSelMonth" style="width: 50px" onchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
日:
<select name="tbSelDay"></select>
<script language="JavaScript">
TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value);
</script>
</form>
</BODY>
</HTML>
你也可以直接下载:
http://cn.ziddu.com/download/264275/date.txt.html
<HTML>
<HEAD>
<TITLE>日历</TITLE>
</HEAD>
<BODY onload="load()">
<SCRIPT LANGUAGE="JavaScript">
function TGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function TUpdateCal(iYear, iMonth) {
var dDate=new Date();
daysInMonth = TGetDaysInMonth(iMonth, iYear);
while(document.all.tbSelDay.childNodes.length>0)
{
document.all.tbSelDay.removeChild(document.all.tbSelDay.childNodes[0]);
}
for (d = 1; d <= parseInt(daysInMonth); d++) {
option=document.createElement("option");
option.value=d;
option.appendChild(document.createTextNode(d));
document.all.tbSelDay.appendChild(option);
if(d==dDate.getDate())
{
option.selected=true;
}
}
}
function load()
{
<!--出始化年-->
var dDate = new Date();
var dCurYear = dDate.getFullYear();
for(var i=dCurYear-10;i<dCurYear+5;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelYear.appendChild(option);
if(i==dCurYear)
{
option.selected=true;
}
}
<!--出始化月-->
for(var i=1;i<=12;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelMonth.appendChild(option);
if(i==(dDate.getMonth()+1))
{
option.selected=true;
}
}
}
</script>
<form name="frmCalendarSample" method="post" action="">
年:
<select name="tbSelYear" onchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
月:
<select name="tbSelMonth" style="width: 50px" onchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
日:
<select name="tbSelDay"></select>
<script language="JavaScript">
TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value);
</script>
</form>
</BODY>
</HTML>
你也可以直接下载:
http://cn.ziddu.com/download/264275/date.txt.html
相关文章推荐
- javascript:Date篇之实现年、月、日下拉列表框的三级联动
- JavaScript实现DropDownList(Select)三级联动无刷新
- JavaScript实现DropDownList(Select)三级联动无刷新 (http://blog.csdn.net/itfly8/archive/2007/07/05/1679102.aspx)
- javascript实现无限级select联动菜单
- asp.net实现DropDownList、ListBox无刷新三级联动(javascript)
- 省市县三级联动 javascript 原生实现实例
- 公众号门店管理开发,实现select表单省市县三级联动1
- 利用select实现年月日三级联动的日期选择效果【推荐】
- Javascript 实现无刷新联动菜单(select)的方法
- JavaScript解析XML实现省市县三级联动
- 用javascript实现三级联动
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用。
- asp.net实现DropDownList、ListBox无刷新三级联动(javascript)
- 使用javascript解析xml实现省市县三级联动
- js使用select实现三级联动
- js实现全国三级城市联动select选择
- javascript三级联动select
- JavaScript实现二级、多级(N级)联动下拉列表框更新版(续)- 四级联动的演示
- JavaScript实现三级联动菜单实例代码
- ajax技术实现select三级联动