js中使用for循环生成select下拉框
yearSel是select的id
for(var i=2000;i<2031;i++){
var newOption = document.createElement("option");
newOption.text=i+"年";
newOption.value=i;
document.getElementById("yearSel").add(newOption);
}
本文介绍了一种使用JavaScript for循环动态创建select下拉框的方法。具体实现为:从2000年至2030年,每年作为一个选项添加到id为yearSel的select元素中。
1万+

被折叠的 条评论
为什么被折叠?



