我有个多选列表框,假设名字为 checkbox,表单的名字为 selectform 请问如何在js中获得多选列表框的值啊
这样为什么不可以呢var course=document.selectform.checkbox.value;请各位大虾赐教

解决方案 »

  1.   

    复选框其实是由多个CHECKBOX组成的,楼主直接这样取值当然拿不到。
    楼主你看下实际的结构就应该知道怎么取值了
      

  2.   

    L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="[email protected]" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
    </head>
    <body>
    <form name="selectform" method="post" action="">
        <select id="checkbox" size="5" multiple>
            <option value="0">要啥</option>
            <option value="1">宝马</option>
            <option value="2">保时捷</option>
            <option value="3">奔驰</option>
            <option value="4">法拉利</option>
        </select>
        <input type="button" value="显示选中值" onclick="ShowSelectValues();" />
    </form>
    <script type="text/javascript">
    <!--
    function ShowSelectValues() {
        var selectedValues = [];
        var opt;
        for (var i=0; i<document.selectform.checkbox.options.length; i++)
        {
            opt = document.selectform.checkbox.options[i];
            if (opt.selected)
                selectedValues.push(opt.value);
        }
        alert(selectedValues.join("\r"));
        return selectedValues;
    }
    //-->
    </script>
    </body>
    </html>
      

  3.   

     Web 开发常用手册DHTML 参考手册
    http://download.csdn.net/source/308913JScript 语言参考
    http://download.csdn.net/source/308916CCS 样式表中文手册
    http://download.csdn.net/source/304124
      

  4.   

    function getValue() {
        var len = document.selectform.checkbox.options.length; 
        var arr = [];
        var opt;
        for (var i=0; i<len; i++)
        {
            opt = document.selectform.checkbox.options[i];
            if (opt.selected)
                arr.push(opt.value);
        }
        alert(arr.join("\r"));
        return arr;
    }