checkbox限制选中个数

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<link href="sysStyle.css" type="text/css" rel="stylesheet"/>
<link href="../crm-css/search.css" type="text/css" rel="stylesheet"/>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function() {

  var isChk=$('#'+idd).is(':checked');//判断是否被选中

$('input[type=checkbox]').click(function() {

$("input[name='apk[]']").attr('disabled', true);

if ($("input[name='apk[]']:checked").length >= 3) {

$("input[name='apk[]']:checked").attr('disabled', false);
alert("选中超过三个");

} else {

$("input[name='apk[]']").attr('disabled', false);

}

});

})

</script>

<ul>

<li>

<input type="checkbox" name="apk[]" value=1 />

APK1

</li>

<li>

<input type="checkbox" name="apk[]" value=2 />

APK2

</li>

<li>

<input type="checkbox" name="apk[]" value=1 />

APK3

</li>

<li>

<input type="checkbox" name="apk[]" value=4 />

APK4

</li>

<li>

<input type="checkbox" name="apk[]" value=6 />

APK5

</li>

<li>

<input type="checkbox" name="apk[]" value=7 />

APK6

</li>

<li>

<input type="checkbox" name="apk[]" value=8 />

APK7

</li>

</ul>

原文地址:https://www.cnblogs.com/yy123/p/4011685.html