这里有个误区吧!Javascript本身是操作不了dropdownlist 的,Dropdownlist是Asp.NET服务器端的东东。
只能说是Javascript去操作Select控件还是可以的,至于说添加删除操作,这个应该不是太难;实现代码如下,可修改仅作参考
<!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>
用jquery:
读取选择项:$("#dropdown option[@selected]").val();
AJAX 要DEMO 加我QQ:283251003给你发一个.