如果select列表框设成多选,在javascript里应该怎么得到他被选中的值?

wzy888 2003-10-17 06:52:46
如果select列表框设成多选,在javascript里应该怎么得到他被选中的值?
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liad 2003-10-17
  • 打赏
  • 举报
回复
<html>
<head>
<title> New Document </title>
<script>
function showSelectedValue()
{

var selectedValue = "";
var objSelect = document.form1.test;
for(var i = 0; i < objSelect.options.length; i++)
{
if (objSelect.options[i].selected == true)
selectedValue += objSelect.options[i].value + "\r\n";
}
alert(selectedValue);
}
</script>
</head>
<body>
<form name="form1">
<select name="test" multiple >
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
<input type="button" value="showSelectedValue" onClick="javascript: {showSelectedValue();}">
</form>
</body>
</html>
weichenggao 2003-10-17
  • 打赏
  • 举报
回复
if(document.all.test[i]==true)
对不起少了个")"
weichenggao 2003-10-17
  • 打赏
  • 举报
回复
<select name="test" onclick="javascript:Select()">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>

在javascript里面
function Select(){
for(var i=0;i<document.all.test.length;i++)
if(document.all.test[i].checked==true
alert(document.all.test[i])
}
这样就可以拉


wzy888 2003-10-17
  • 打赏
  • 举报
回复
大哥,能明确一点么?
我刚开始用javascript。谢谢
qdubit 2003-10-17
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE=javascript>
<!--
var prv=new Array()//医院
var cty=new Array()//级别
var khlb=new Array()//类别
function init(){
<%
dim prv,cty,khlb,i,j,k
dim sq1
i=0
//sq1=document.frm.sq.value
set prv=conn.execute("select yy_mingcheng from sale_manage_khda_mbyyda where dy_bianma='"&s_dy_bianma&"' order by yy_mingcheng")
if not prv.eof then
do while not prv.eof
j=0
k=0
%>
prv[<%=i%>]="<%=trim(prv("yy_mingcheng"))%>";
<%
set cty=conn.execute("select yylb_mingcheng from sale_manage_bianma_yylb as a join sale_manage_khda_mbyyda as b on b.yy_leibie=a.yylb_bianma where b.yy_mingcheng = '"&trim(prv("yy_mingcheng"))&"'")
if not cty.eof then%>
cty[<%=i%>]=new Array()
<%do while not cty.eof%>
cty[<%=i%>][<%=j%>]="<%=trim(cty("yylb_mingcheng"))%>"
<%j=j+1
cty.movenext
loop
end if
cty.close :set cty=nothing
%>
<%
set khlb=conn.execute("select khb_shuoming from sale_base_khlx as a join sale_manage_khda_mbyyda as b on b.khb_bianma=a.khb_bianma where b.yy_mingcheng = '"&trim(prv("yy_mingcheng"))&"'")
if not khlb.eof then%>
khlb[<%=i%>]=new Array()
<%do while not khlb.eof%>
khlb[<%=i%>][<%=k%>]="<%=trim(khlb("khb_shuoming"))%>"
<%k=k+1
khlb.movenext
loop
end if
khlb.close :set khlb=nothing

i=i+1
prv.movenext
loop
end if
prv.close :set prv=nothing
%>
if(prv.length >0){
for(i=0;i<prv.length;i++)
with(document.frm.province)options[length]=new Option(prv[i],prv[i])
document.frm.province.onchange=new Function("go(this.selectedIndex)")
}
}

function go(sIndex){
with(document.frm.city){
length=0;
if(sIndex==0){options[0]=new Option("显示医院级别");return}
for(i=0;i<cty[sIndex-1].length;i++)
options[length]=new Option(cty[sIndex-1][i],cty[sIndex-1][i])
}
with(document.frm.yylb){
length=0;
if(sIndex==0){options[0]=new Option("显示医院类别");return}
for(i=0;i<khlb[sIndex-1].length;i++)
options[length]=new Option(khlb[sIndex-1][i],khlb[sIndex-1][i])
}
}
window.onload=init
-->
</SCRIPT>

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧