jquery,获取多个复选框的值

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="../css/mui.min.css" rel="stylesheet" />
    </head>

    <body>
        <input type="checkbox" name="test" value="1" /><span>1</span>
        <input type="checkbox" name="test" value="2" /><span>2</span>
        <input type="checkbox" name="test" value="3" /><span>3</span>
        <input type="checkbox" name="test" value="4" /><span>4</span>
        <input type="checkbox" name="test" value="5" /><span>5</span>
        <input type='button' value='提交' onclick="show()" />
        <script src="../js/plugins/jquery-3.2.1.min.js"></script>
        <script type="text/javascript">
            function show() {
                obj = document.getElementsByName("test");
                console.log(obj);
                check_val = [];
                for(k in obj) {
                    if(obj[k].checked)
                        check_val.push(obj[k].value);
                }
                alert(check_val);
            }
        </script>
    </body>

</html>

猜你喜欢

转载自blog.csdn.net/Generon/article/details/81475303