已经在另一贴做了回复:代码如下
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="Sel">
<option value="0">==我是默认项==</option>
</select><input id="g" value="获取Select所有项" type="button" />
<hr />
<label>添加项</label><input id="c" value="Item1" />
<input value="Add" id="Add" type="button" /><input value="Del Selected" id="Del" type="button" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
var add = $("Add"), del = $("Del"), sel = $("Sel");
add.onclick = function() {
var opt = document.createElement("OPTION");
opt.value = $("c").value;
opt.text = $("c").value;
sel.options.add(opt);
}
del.onclick = function() {
var v = [], t = [];
for (var i = 0; i < sel.length; i++) {
if (sel[i].selected) {
sel.remove(i);
}
}
}
$("g").onclick = function() {
for (var str = "", i = 0; i < sel.length; i++) {
str += sel[i].value + "**";
}
if (sel.length > 1)
alert(str);
}
</script>
var opt = document.createElement("OPTION");
opt.text="select 1";
opt.value="value 1";
dropdownlist1.add(opt);