有段代码如下
<form id="sa" name="sa" method="post" action="sa.php">
<fieldset>
<table id="show_post" class="tablesorter" border="0.5">
<tr>
<td>部门</td>
<td>
<select name="department[]" id="department[]" multiple="multiple" size = "4">
<option value="abc">abc</option>
<option value="da">da</option>
<option value="aaa">aaa</option>
<option value="ccc">ccc</option>
</select>
</td>
</tr>
<tr>
<td><input type="button" value="预览" onclick="show_confirm()" ></input></td>
 <td><input type="submit" value="提交" class="button" ></input></td>
</tr>
</table>
</fieldset>
</form>   
function show_confirm()
{
alert("部门:"+document.sa.department[].options[document.sa.department[].selectedIndex].value);}
我想预览 options选中的内容 用alert弹出,请问怎么实现?谢谢

解决方案 »

  1.   

    var arr=[];
    for(var p in document.sa.department[].options){
    if(p.checked)arr.push(p);
    }
    alert("部门:"+ arr.join(','));
      

  2.   

    <select name="department[]" id="department[]" multiple="multiple" size = "4">
     变成
    <select name="department" id="department" multiple="multiple" size = "4">
    alert("部门:"+document.sa.department[].options[document.sa.department[].selectedIndex].value);
     变成
    alert("部门:"+document.sa.department.options[document.sa.department.selectedIndex].value);
      

  3.   

    function show_confirm()
     { 
     
    var arr=[];
    var p = document.getElementById("department[]").options;
    for(var i=0;i< p.length;i++){
    if(p[i].selected){arr.push(p[i].value);}
    }
    alert("部门:"+ arr.join(','));
     
      }选中是 selected 。我搞成 checkbox 了
      

  4.   

    function DF_getOptionText(fd){field=eval("document.all('"+fd+"');");
    for (i=0;i<field.length;i++) {ss=field[i].nextSibling.nodeValue;
    alert(ss);
    }}
    这是方法,运行这个方法就可以了DF_getOptionText("department[]")
      

  5.   

    function DF_getOptionText(fd){
    ss="";
    field=eval("document.all('"+fd+"');");
    for (i=0;i<field.length;i++) {
    if (field[i].checked==true)
    {
    ss=field[i].nextSibling.nodeValue;break;
    }
    }
    return ss;
    }
    这是返回选中的值的方法