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> 这是以前在学校的时候弄的,现在也忘得差不多了,你自己看看。
大哥能把html也写上马?我很难看的懂啊!还有是那个对象触发函数我都不知道,看不懂
<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> 基本就这样...
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>