效果如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>增加页面中下拉列表框中的列表项目</title>
</head>
<script language="javascript" type="text/javascript">
var i,txt,val;
window.onload = function() {
var btnobj = document.getElementById("testbtn");
if(btnobj)
{
btnobj.onclick = function() { InsertItem() };
}
i=0;
}
function InsertItem()
{
i++;
var testlistobj = document.getElementById("testlist");
var option;
txt = "新增下拉列表项目" + i.toString();
val = txt + i.toString();
option = new Option(txt, val);
if(testlistobj)
{
testlistobj.options.add(option);
}
}
</script>
<body>
<select id="testlist">
</select>
<input id="testbtn" type="button" value="增加列表项目">
</body>
</html>