年月日三联动下拉框
2007-03-28 16:46
260 查看
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<HTML>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<HEAD>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<title>年月日三联动下拉框</title>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<meta name='author' content='http://singlepine.cnblogs.com/'>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</HEAD>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<body>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<form name="form1">
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<select name="YYYY" onchange="YYYYDD(this.value)">
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<option value="" selected>请选择 年</option>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</select>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<select name="MM" onchange="MMDD(this.value)">
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<option value="" selected>选择 月</option>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</select>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<select name="DD">
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<option value="" selected>选择 日</option>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</select>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</form>
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
<script language="JavaScript">
![](http://www.cnblogs.com/Images/dot.gif)
<!--
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function YYYYMMDDstart()
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//先给年下拉框赋内容
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var y = new Date().getFullYear();
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
for (var i = (y-30); i < (y+30); i++) //以今年为准,前30年,后30年
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
document.form1.YYYY.options.add(new Option(" "+ i +" 年", i));
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//赋月份的下拉框
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
for (var i = 1; i < 13; i++)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
document.form1.MM.options.add(new Option(" " + i + " 月", i));
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
document.form1.YYYY.value = y;
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
document.form1.MM.value = new Date().getMonth() + 1;
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var n = MonHead[new Date().getMonth()];
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
writeDay(n); //赋日期下拉框
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
document.form1.DD.value = new Date().getDate();
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if(document.attachEvent)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
window.attachEvent("onload", YYYYMMDDstart);
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
else
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
window.addEventListener('load', YYYYMMDDstart, false);
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var MMvalue = document.form1.MM.options[document.form1.MM.selectedIndex].value;
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
if (MMvalue == "")
![](http://www.cnblogs.com/Images/dot.gif)
{ var e = document.form1.DD; optionsClear(e); return;}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var n = MonHead[MMvalue - 1];
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (MMvalue ==2 && IsPinYear(str)) n++;
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
writeDay(n)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function MMDD(str) //月发生变化时日期联动
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var YYYYvalue = document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value;
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
if (YYYYvalue == "")
![](http://www.cnblogs.com/Images/dot.gif)
{ var e = document.form1.DD; optionsClear(e); return;}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var n = MonHead[str - 1];
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (str ==2 && IsPinYear(YYYYvalue)) n++;
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
writeDay(n)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function writeDay(n) //据条件写日期的下拉框
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var e = document.form1.DD; optionsClear(e);
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
for (var i=1; i<(n+1); i++)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
e.options.add(new Option(" "+ i + " 日", i));
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function IsPinYear(year)//判断是否闰平年
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return(0 == year%4 && (year%100 !=0 || year%400 == 0));
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function optionsClear(e)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
e.options.length = 1;
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//-->
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
</script>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</body>
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
</HTML>
相关文章推荐
- JS 年月日三下拉框联动
- 年月日三下拉框联动
- html年月日下拉联动菜单 年月日三下拉框联动
- 年月日三联动下拉框
- 年月日三联动下拉框
- 年月日三下拉框联动
- 年月日三联动下拉框
- html年月日下拉联动菜单 年月日三下拉框联动
- 年月日下拉联动代码
- JS年月日三级联动下拉框日期选择代码
- [JS]年月日三下拉框无刷新联动
- html年月日下拉联动菜单 年月日三下拉框联动
- 年月日三下拉框联动
- html年月日下拉联动菜单 年月日三下拉框联动
- js 自定义的联动下拉框
- javascript省市区三级联动下拉框菜单实例演示
- MVC 页面实现ajax刷新联动下拉列表
- extJs 下拉框联动实现代码
- jquery 下拉框联动(1)
- Ajax实现无刷新三联动下拉框