js动态添加菜单

<script type="text/javascript">window.onload = initForm; 
  
function initForm() {
     document.getElementById("months").selectedIndex = 0;
     document.getElementById("months").onchange = populateDays;
}
  
function populateDays() {
     var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
     var monthStr = this.options[this.selectedIndex].value;
  
     if (monthStr != "") {
        var theMonth = parseInt(monthStr);
        document.getElementById("days").options.length = 0;
        for(var i=0; i<monthDays[theMonth];i++) {
           document.getElementById("days").options[i] = new Option(i+1);
        }
     }
}
</script>

 

posted on 2015-02-11 22:54  梦想->路  阅读(233)  评论(0)    收藏  举报

导航