- <html>
- <head>
- <title>中国站长天空-网页特效-表单特效-日期选择下拉框</title>
- <meta http-equiv="content-Type" content="text/html;charset=gb2312">
- </head>
- <body>
- <!--把下面代码加到<body>与</body>之间-->
- <SCRIPT>
- now = new Date();
- function writeYears(obj, date)
- {
- var years = date.getYear()+100
- for (var i=1949; i<2010; i++)
- {
- var opt = document.createElement("option")
- opt.text = opt.value = i
- obj.add(opt)
- }
- }
- function writeMonths(obj)
- {
- for (var i=1; i<13; i++)
- {
- var opt = document.createElement("option")
- opt.text = opt.value = Math.floor(i/10) ? i : "0"+i
- obj.add(opt)
- }
- }
- function writeDate(obj, year, month)
- {
- var date = new Date(""+year+"/"+(parseInt(month)+1)+"/"+0).getDate()
- var selectedIndex = (date-1)<obj.selectedIndex ? (date-1) : obj.selectedIndex
- var len = obj.options.length
- if (date>len)
- for (var i=len+1; i<=date; i++)
- {
- var opt = document.createElement("option")
- opt.text = opt.value = Math.floor(i/10) ? i : "0"+i
- obj.add(opt)
- }
- else
- for (var i=date; i<len; i++)
- {
- obj.remove(obj.length-1)
- }
- obj.selectedIndex = selectedIndex
- }
- function changeDate()
- {
- var c_year = eval("document.forms[0].c_year")
- var c_month = eval("document.forms[0].c_month")
- var c_day = eval("document.forms[0].c_day")
- writeDate(c_day, c_year.options(c_year.selectedIndex).value, c_month.options(c_month.selectedIndex).value)
- }
- </SCRIPT>
- <FORM><SELECT οnchange=changeDate() name=c_year></SELECT>年<SELECT οnchange=changeDate() name=c_month></SELECT>月<SELECT name=c_day></SELECT>日</FORM>
- <SCRIPT language=javascript type=text/javascript>
- writeYears(document.forms[0].c_year, now)
- document.forms[0].c_year.value = now.getYear()
- writeMonths(document.forms[0].c_month)
- this_month = now.getMonth()+1
- if (this_month<10){this_month = "0"+this_month}
- document.forms[0].c_month.value = this_month
- writeDate(document.forms[0].c_day, now.getYear(), now.getMonth()+1)
- nowday = now.getDate()
- if (nowday<10){nowday="0"+(now.getDate())*1}
- document.forms[0].c_day.value = nowday
- </SCRIPT>
- </body>
- </html>
日期选择下拉框
最新推荐文章于 2022-02-23 15:02:25 发布