jquery判断checkbox最多选几个

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="js/jquery.min.js"></script>
</head>
<body>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<div class="checkbox">
    <input type="checkbox"/>
</div>
<script type="text/javascript">
$(function(){
    $('.checkbox').find('input').click(function(){

        if($("input[type=checkbox]:checked").length >= 6)

        {

            $(this).removeAttr("checked");

            alert("最多选5个!")}

    });
})
</script>

posted @ 2016-01-13 16:04  盗梦者  阅读(1082)  评论(0编辑  收藏  举报