三级联动有点复杂,希望哪位大神帮组我一下,写一个简单的三级联动,最好是年月日的,thank you
解决方案 »
- 右下角弹出窗口关闭问题,请教
- JavaScript 怎么动态加载内容啊??
- IE8.0执行JavaScript的速度为什么那么慢?
- 向各位求教!
- 请教一个正则 替换HTML中所有<TAG>之外的东西 AA为BB
- 高手求翻译...这个段JS 脚本什么意思
- 怎么在xp下窗口关闭时把弹出的窗口给关掉了,帮帮忙?急呀!
- 关于脚本中调用window.open()的问题
- 如何在页面中定义一个层,并使其在最上面,还需要接受键盘输入
- 如何通过document.all返回得到一张HTML页面中所有的Table对象(没有定义ID和name)?
- js如何实现选中文本后点击按钮变色
- 【求助】jquery-lightbox-0.5(中文字符串不显示)
function YYYYMMDDstart() {
MonHead = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; var y = new Date().getFullYear(); for ( var i = (y - 30); i < (y + 30); i++) {
document.all.YYYY.options.add(new Option(i, i));
}
for ( var i = 1; i < 13; i++) {
if (i >= 10)
document.all.MM.options.add(new Option(i, i));
else
document.all.MM.options.add(new Option("0" + i, "0" + i));
} document.all.YYYY.value = y;
if ((new Date().getMonth() + 1) >= 10)
document.all.MM.value = new Date().getMonth() + 1;
else
document.all.MM.value = "0"
+ (new Date().getMonth() + 1).toString();
var n = MonHead[new Date().getMonth()];
if (new Date().getMonth() == 1 && IsPinYear(YYYYvalue))
n++;
writeDay(n); //¸³ÈÕÆÚÏÂÀ¿ò
if (new Date().getDate() < 10)
document.all.DD.value = "0" + new Date().getDate();
else
document.all.DD.value = new Date().getDate();
}
if (document.attachEvent)
window.attachEvent("onload", YYYYMMDDstart);
else
window.addEventListener('load', YYYYMMDDstart, false);
function YYYYDD(str)
{ var MMvalue = document.all.MM.options[document.all.MM.selectedIndex].value;
if (MMvalue == "") {
var e = document.all.DD;
optionsClear(e);
return;
}
var n = MonHead[MMvalue - 1];
if (MMvalue == 2 && IsPinYear(str))
n++;
writeDay(n)
}
function MMDD(str)
{
var YYYYvalue = document.all.YYYY.options[document.all.YYYY.selectedIndex].value;
if (YYYYvalue == "") {
var e = document.all.DD;
optionsClear(e);
return;
}
var n = MonHead[str - 1];
if (str == 2 && IsPinYear(YYYYvalue))
n++;
writeDay(n)
}
function writeDay(n)
{
var e = document.all.DD;
optionsClear(e);
for ( var i = 1; i < (n + 1); i++) {
if (i >= 10)
e.options.add(new Option(i, i));
else
e.options.add(new Option("0" + i, "0" + i));
}
}
function IsPinYear(year)
{
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
function optionsClear(e) {
e.options.length = 1;
}
</script>
这是以前在学校的时候弄的,现在也忘得差不多了,你自己看看。
<script language="JavaScript">
function YYYYMMDDstart() {
MonHead = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; //ÏȸøÄêÏÂÀ¿ò¸³ÄÚÈÝ
var y = new Date().getFullYear(); for ( var i = (y - 30); i < (y + 30); i++) {
//ÒÔ½ñÄêΪ׼£¬Ç°30Ä꣬ºó30Äê
document.all.YYYY.options.add(new Option(i, i));
}
//¸³Ô·ݵÄÏÂÀ¿ò
for ( var i = 1; i < 13; i++) {
if (i >= 10)
document.all.MM.options.add(new Option(i, i));
else
document.all.MM.options.add(new Option("0" + i, "0" + i));
} document.all.YYYY.value = y;
if ((new Date().getMonth() + 1) >= 10)
document.all.MM.value = new Date().getMonth() + 1;
else
document.all.MM.value = "0"
+ (new Date().getMonth() + 1).toString();
var n = MonHead[new Date().getMonth()];
if (new Date().getMonth() == 1 && IsPinYear(YYYYvalue))
n++;
writeDay(n); //¸³ÈÕÆÚÏÂÀ¿ò
if (new Date().getDate() < 10)
document.all.DD.value = "0" + new Date().getDate();
else
document.all.DD.value = new Date().getDate();
}
if (document.attachEvent)
window.attachEvent("onload", YYYYMMDDstart);
else
window.addEventListener('load', YYYYMMDDstart, false);
function YYYYDD(str) //Äê·¢Éú±ä»¯Ê±ÈÕÆÚ·¢Éú±ä»¯(Ö÷ÒªÊÇÅжÏÈòƽÄê)
{ var MMvalue = document.all.MM.options[document.all.MM.selectedIndex].value;
if (MMvalue == "") {
var e = document.all.DD;
optionsClear(e);
return;
}
var n = MonHead[MMvalue - 1];
if (MMvalue == 2 && IsPinYear(str))
n++;
writeDay(n)
}
function MMDD(str) //Ô·¢Éú±ä»¯Ê±ÈÕÆÚÁª¶¯
{
var YYYYvalue = document.all.YYYY.options[document.all.YYYY.selectedIndex].value;
if (YYYYvalue == "") {
var e = document.all.DD;
optionsClear(e);
return;
}
var n = MonHead[str - 1];
if (str == 2 && IsPinYear(YYYYvalue))
n++;
writeDay(n)
}
function writeDay(n) //¾ÝÌõ¼þдÈÕÆÚµÄÏÂÀ¿ò
{
var e = document.all.DD;
optionsClear(e);
for ( var i = 1; i < (n + 1); i++) {
if (i >= 10)
e.options.add(new Option(i, i));
else
e.options.add(new Option("0" + i, "0" + i));
}
}
function IsPinYear(year)//ÅжÏÊÇ·ñÈòƽÄê
{
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
function optionsClear(e) {
e.options.length = 1;
}
</script><td width="196" align="left" valign="middle">
<select name="YYYY" onchange="YYYYDD(this.value)">
<option value=""></option>
</select>
<select name="MM" onchange="MMDD(this.value)">
<option value=""></option>
</select>
<select name="DD">
<option value=""></option>
/select>
</td>
基本就这样...
<td width="196" align="left" valign="middle">
<select name="YYYY" onchange="YYYYDD(this.value)">
<option value=""></option>
</select>
<select name="MM" onchange="MMDD(this.value)">
<option value=""></option>
</select>
<select name="DD">
<option value=""></option>
</select>
</td>