循环方式为select下拉菜单添加年份
分类:实例代码
循环方式为select下拉菜单添加年份属于前端实例代码,有关更多实例代码大家可以查看。
在网站中有有选择出生年月的下拉菜单,如果人工方式添加的话,工作量会很大。
下面介绍一下如何利用JavaScript动态循环添加年份。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <script type="text/javascript"> function gel(id){ return document.getElementById(id); } window.onload=function(){ var cbbYear=gel("sel"); for(var i=2000;i<2014;i++){ var opt=new Option(i, i); cbbYear.options.add(opt); } } </script> </head> <body> <select id="sel"> </select> </body> </html>
循环方式为select下拉菜单添加年份,这样的场景在实际项目中还是用的比较多的,关于循环方式为select下拉菜单添加年份就介绍到这了。