怎么动态给select添加数据
展开全部
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="">
<select name="list" size="1" onChange="doChange()"></select>
</form>
</body>
</html>
<script language="javascript">
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);
}
</script>
如上,直接新增 Option 对象就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询