码迷,mamicode.com
首页 > 其他好文 > 详细

checkbox的全选,取消全选,获得选中值

时间:2016-07-06 20:04:03      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>
<title>jq全选以及获得选中项的值</title>
<meta charset="utf-8">

<script src="http://libs.baidu.com/jquery/1.4.1/jquery.js"></script>
<script>
$(function() {
    $("#select").click(function() {
        if ($(this).attr("checked")) {
            $("input[name=items]").each(function() {
                $(this).attr("checked", true);
            });
        } else {
            $("input[name=items]").each(function() {
                $(this).attr("checked", false);
            });
        }
    });
    //得到选中的值,ajax操作使用
    $("#submit").click(function() {
        var text="";
        $("input[name=items]").each(function() {
            if ($(this).attr("checked")) {
                text += ","+$(this).val();
            }
        });
         alert(text);
    });
});
</script>
</head>
<body>
<form action="#" method="post">
    <input type="checkbox" value="1" name="items"><br/>
    <input type="checkbox" value="2" name="items"><br/>
    <input type="checkbox" value="3" name="items"> <br/>
    <input type="checkbox" value="4" name="items"> <br/>
    <input type="checkbox" value="5" name="items"> <br/>
    <input type="checkbox" value="6" name="items"> <br/>
    <input type="checkbox" value="7" name="items"> <br/>
    <input type="checkbox" value="8" name="items"> <br/>
    <input type="checkbox" value="9" name="items"> <br/>
    <input type="checkbox" value="10" name="items"> <br/>
    <input type="checkbox" value="11" name="items"> <br/>
	<input type="checkbox" id="select"/> 全选<br/>
    <input type="submit" id="submit" value="提交">
</form>
</body>
</html>

  好像高版本的jq库会有问题,待研究。。。。。

checkbox的全选,取消全选,获得选中值

标签:

原文地址:http://www.cnblogs.com/phpjinggege/p/5647736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!