---
title: "JQuery限制复选框checkbox可选中个数"
author: "goby2008"
date: "2012-12-16T16:33:14Z"
tags: []
categories: ["Web前端"]
slug: "jquery-checkbox"
draft: false
lastmod: "2012-12-16T16:33:14Z"
id: 1748665
url: "https://goby2008.iteye.com/blog/1748665"
---

```
<script type="text/javascript">
	$(document).ready(function() {

		$('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);
			} 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>
```