<select id="a" multiple>
<option value="1" >1
<option value="2">1
<option value="3">1
<option value="4">1</select>
<input type=button onclick="aa()">
<script>
function aa(){
var s = "";
for(var i=0;i<document.all.a.options.length;i++)
{
if(document.all.a.options[i].selected)
{s += document.all.a.options[i].value;}
}
alert(s);}
</script>
<option value="1" >1
<option value="2">1
<option value="3">1
<option value="4">1</select>
<input type=button onclick="aa()">
<script>
function aa(){
var s = "";
for(var i=0;i<document.all.a.options.length;i++)
{
if(document.all.a.options[i].selected)
{s += document.all.a.options[i].value;}
}
alert(s);}
</script>
解决方案 »
- 怎么样遍历js 对象属性,控制循环次数?
- var fAppVersion=parseFloat(navigator.appVersion);
- 如何让伸缩菜单里的超级联接是弹出新窗口的
- 正则表达式 转义了不需要转义的字符,好像也没出错,为什么
- 怎么用javascript改变层的位置
- 如何得到当前窗口的坐标
- js 执行等待的问题
- js中读取数据流
- 请问如何实现两个select的动态对应。
- 如何把一组广告插入到包含文件内?
- 一个有点难度的问题;怎样用javascript实现象windows的帮助文档内的索引查询功能(输入某字符后自动显示关于该字的项目
- 怎样使用execCommand("CreateBookmark")
如是在页面用js, wangxj0600(闭门思过中) 的例子就行了
如是提交到asp,则提交的已是数组
如市提交到php,需将select的名字以数组形式表示,提交后也是数组
<option value="1" >1
<option value="2">1
<option value="3">1
<option value="4">1</select>
<input type=button onclick="aa()">
<script>
function aa(){
var s = new Array();
var j = 0;
for(var i=0;i<document.all.a.options.length;i++)
{
if(document.all.a.options[i].selected)
{s[j++] += document.all.a.options[i].value;}
}
alert(s.length);}
</script>
<option value="1" >1
<option value="2">1
<option value="3">1
<option value="4">1</select>
<input type=button onclick="aa()">
<script>
function aa(){
var s = new Array();
var j = 0;
for(var i=0;i<document.all.a.options.length;i++)
{
if(document.all.a.options[i].selected)
{s[j++] += document.all.a.options[i].value;}
}
alert(s);}
</script>