<option selected>为什么显示不出来?!
我初学Javascript,这个例子也是书上来的。
功能是在下拉菜单里显示当月月历,并把当日设为选中状态,但是不知道为什么当日的选项总是无法显示。我调试过,但看不出什么名堂来。请教各位大侠。
代码很简单,如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示当月月历表</title>
</head>
<body>
<script language=javascript>
<!--
var maxdays;
var today = new Date();
thismonth = today.getMonth() +1;
thisyear = today.getFullYear();
thisday = today.getDate();
switch(thismonth)
{
case 4:
case 6:
case 9:
case 11:
maxdays = 30;
break;
case 2:
if((thisyear%400==0)||(thisyear%4==0 && thisyear%100!=0))
maxdays = 29;
else maxydays = 28;
break;
default:
maxdays = 31;
break;
}
if(thismonth<=9) thismonth = "0" +thismonth;
document.write("<form>");
document.write("<select name=dates size=1>");
for(var theday=1;theday<=maxdays;theday++)
{
document.write("<option");
if(theday == thisday) document.write("selected");
document.write(">");
if(theday<=9) theday = "0" + theday;
document.write(thismonth + "-" + theday + "-" + thisyear);
document.write("</option>")
}
document.write("</select></form>");
//-->
</script>
</body>
</html>
问题点数:40、回复次数:2Top
1 楼fosjos(无聊的菜鸟程序员)回复于 2006-05-01 16:54:35 得分 40
document.write("<option");
if(theday == thisday)document.write("selected");
改成:
document.write("<option");
if(theday == thisday)document.write(" selected");//option和selected间加个空格^_^
Top
2 楼sharpteeth(agong)回复于 2006-05-01 20:25:38 得分 0
哦~原来这样啊!您真仔细呃~
唉,真粗心,我~Top




