通过js获取select(多选下拉)中所选值

来源:互联网 发布:腾讯云域名续费 编辑:程序博客网 时间:2024/05/17 01:11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>

<script language="JavaScript">
<!--
function checkselect(){
var x = document.getElementById("objsel");
var t = document.getElementById("output");
var count=0;
var intvalue="";
for(i=0;i<x.length;i++){
if(x.options[i].selected){
intvalue+=x.options[i].value+",";
count++;
}
}
t.value=intvalue.substr(0,intvalue.length-1);
alert(count);

}
//-->
</script>
<select id="objsel" name="objsel" size=8 multiple>
<option value="0" selected>请选择
<option value="1">测试一
<option value="2">测试二
<option value="3">测试三
<option value="4">测试四
<option value="5">测试五
</select>
<input type="button" onclick="checkselect();" value="输出">
选中的项目:<input type="text" id="output" name="output">
</body>
</html>
0 1
原创粉丝点击