JQ-获取选中的Checkbox

使用JQuery获取选中的Checkbox:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <input type="checkbox" name="test" value="1" checked/>
    <input type="checkbox" name="test" value="2" checked/>
</body>
<script type="text/javascript">
    //选中状态数组的长度
    console.log($(":checked").length);
    $(":checked").each(function (index, value) {
        //index是循环下标,从0开始
        console.log(index + ":" + $(this).val());
    });
</script>
</html>

猜你喜欢

转载自blog.csdn.net/wang704987562/article/details/81043309