javascript 下拉框显示当前日期(2)


[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]


第三种方法:不能用,但编程思路还可以,如果正式使用建议用第二种方法

复制代码 代码如下:


<html>
<head>
<title> New Document </title>
</head>
<body>
<script>
function setDay(obj){
obj = obj.form;
var years=parseInt(obj.years.options[obj.years.selectedIndex].value);
var months=parseInt(obj.months.options[obj.months.selectedIndex].value);
if(obj.years.selectedIndex==0 || obj.months.selectedIndex==0)return;
var lastday = monthday(years,months);
var itemnum = obj.days.length;
if (lastday - 1 < obj.days.selectedIndex)
{
obj.days.selectedIndex = lastday - 1;
}
obj.days.length = lastday;
for(cnt = itemnum + 1;cnt <= lastday;cnt++)
{
obj.days.options[cnt - 1].text = cnt;
}
}
function monthday(years,months)
{
var lastday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (((years % 4 == 0) && (years % 100 != 0)) || (years % 400 == 0))
{
lastday[1] = 29;
}
return lastday[months - 1];
}
function forto(ff,to)
{
document.write('<OPTION value=""></OPTION>');
for(var ii=ff; ii<=to; ii++)
document.write('<OPTION value="'+ii+'">'+ii+'</OPTION>');
}
function a()
{
alert(document.all("years").value+"年"+document.all("months").value+"月"+document.all("days").value+"日") ;
}
</script>
<FORM>
<SELECT onChange="setDay(this);">
<script>forto(1990,2030)</script>
</SELECT>年 
<SELECT onChange="setDay(this);">
<script>forto(1,12)</script>
</SELECT>月 
<SELECT></SELECT>日 
</form>
</body>
</html>


您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjggdp.html