//通过判断$("#btn1")这个集合中对象的个数来判断是否有对象存在(可行)
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$('#allOrNone').click(function () {
$(':checkbox').attr('checked', $(this).attr('checked'));
//当改变了上面选择项的选中状态后,“选择状态”的状态也跟着改变
$(':checkbox[id!=allOrNone]').click(function () {
function optionStateChanged() {
$(':checkbox[id!=allOrNone]').each(function () {
if (!$(this).attr('checked')) {
//如果有一个没有被选中,则将“选择状态”的状态也设置为没有选中状态
$('#allOrNone').attr('checked', state);
$('#chooseReverse').click(function () {
$(':checkbox[id!=allOrNone]').each(function () {
$(this).attr('checked', !$(this).attr('checked'));
<input type="checkbox" value="1" />足球
<input type="checkbox" value="2" />足球
<input type="checkbox" value="3" />足球
<input type="checkbox" value="4" />足球
<input type="checkbox" value="5" />足球<br />
<input type="checkbox" name="name" value="" id="allOrNone"/>选择状态
<input type="button" name="name" value="反选" id="chooseReverse"/>
联系客服