下拉菜单

用javascript动态生成select下拉菜单,然后用jquery获取下拉菜单的值

 1 <script type="text/javascript" src="<%=path %>/web/js/jquery/lib/jquery-1.4.js"></script>    
 2 <script type="text/javascript">
 3     function create(){
 4         var value = $("#myselect").val();
 5         alert(value);
 6     };
 7     document.write("<form name='myform'><TABLE height='20%' cellSpacing=0 cellPadding=0 width='100%' bgColor=#b0e0e6 border=0>");
 8     document.write("<tr><td>&nbsp;&nbsp;&nbsp账期:");
 9     document.write("<select id='myselect'>");
10         var year =2000;
11         var month =1;
12         for(var i=0;i<2400;i++){
13             if(month>12){
14                 year++;
15                 month=1;
16             }
17             var datestr = year+"年"+month+"月";
18             if(year==2013 && month==5 ){
19                 document.write("<option selected='selected'>"+datestr+"</option>");//默认当前选中值
20                 }else{
21                     document.write("<option >"+datestr+"</option>");
22                 }
23             month++;
24         }
25     document.write("</select></td>");
26     document.write("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
27     document.write("<span style='font-size:14px;'><a href='javascript:void(0);' onclick='create()' >生成账期</a></span></td>");
28     document.write("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
29     document.write("<span style='font-size:14px;'><a href='www.baidu.com'>删除账期</a></span></td>");
30     document.write("</tr></TABLE></form>");
31 </script>
动态生成下拉菜单
原文地址:https://www.cnblogs.com/zhutouying/p/3259164.html