復制代碼 代碼如下:
<script type="text/javascript">
function GetValue() {
var strlist = document.getElementById("ListBox1");//獲取Listbox
var str= "";
//遍歷Listbox,取得選中項的值
if (strlist.options.length > 0) {
for (var i = 0; i < strlist.options.length; i++) {
if (strlist.options[i].selected == true) {
var j = strlist.options[i].value;
str+=j+","; //把Value值串起來
}
}
var strValue=str.replace(/,$/, ""); //去掉最後一個逗號
alert(strValue);
}
else {
alert("No Item in Listbox");
}
}
</script>