怎么动态给select添加数据

2025-04-18 15:15:53
推荐回答(1个)
回答1:
















var yearList = new Array();

for(var i=0; i<10; i++)
{
yearList[i] = i;
}

for(var i=0; i<10; i++)
{
document.form1.list.options[i] = new Option(yearList[i],yearList[i]);
}
document.form1.list.length = 10;

function doChange()
{
var index = document.form1.list.selectedIndex;
var countryName = document.form1.list.options[index].value;
alert(index+" "+countryName);
}

如上,直接新增 Option 对象就可以了