首页 > 其他 > 详细

下拉菜单年月日

时间:2015-04-24 11:49:52      阅读:189      评论:0      收藏:0      [点我收藏+]
 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>网站首页</title>
 6 <style>
 7 </style>
 8 </head>
 9 <body>
10 <select id="yy"></select>年
11 <select id="mm"></select>月
12 <select id="dd"></select>日
13 </body>
14 </html>
15 <script>
16 function $(id){
17     return document.getElementById(id);
18 }
19 function list(id,start,end){
20     var d=new Date();
21     var o=$(id);
22     o.options.length=end-start+1;
23     for(var i=0;i<o.options.length;i++){
24         var tt=start+i;
25         o.options[i].text=tt;
26         o.options[i].value=tt;
27         if(tt==d.getFullYear()){
28             o.options[i].selected=true;
29         }else if(tt==d.getMonth()+1){
30             o.options[i].selected=true;
31         }else if(tt==d.getDate()){
32             o.options[i].selected=true;        }    
33     }
34 }
35 //此段代码控制对应的年月日有对应的日期
36 list(‘yy‘,2000,2015);
37 list(‘mm‘,1,12);
38 list(‘dd‘,1,31);
39 $(‘mm‘).onchange=$(‘yy‘).onchange=function(){
40     var da=new Date($(‘yy‘).value,$(‘mm‘).value,0)
41     list(‘dd‘,1,da.getDate());
42 }
43 </script>

 

下拉菜单年月日

原文:http://www.cnblogs.com/lsr111/p/4452755.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!