Posted in Javascript onMay 23, 2014
javascript为下拉列表添加数据项.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>为下拉列表动态添加数据项</title> <script type="text/javascript"> function gel(id) { return document.getElementById(id); } window.onload = function() { var cbbYear = gel("mysel"); for (var i = 1990; i < 2014; i++) { //方法1 /*var opt = document.createElement("option"); opt.innerHTML = i; cbbYear.appendChild(opt);*/ //方法2 var opt = new Option(i, i); cbbYear.options.add(opt); } }; </script> </head> <body> <select id="mysel"> </select> </body> </html>
javascript为下拉列表动态添加数据项
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@