console
$("#all").toggle(function(){
$(".class input").attr("checked",true);
},function(){
$(".class input").attr("checked",false);
})
$("#Inverse").on("click",function(){
$(".class input").each(function(){
$(this).attr("checked", !$(this).attr("checked"));
})
})
$("#get").on("click",function(){
var sChecked = "";
$(".class input:checked").each(function(){
sChecked += $(this).val();
$("#content").text(sChecked);
})
})
<form class="class">
<input type="checkbox" value="一年级"/>一年级
<input type="checkbox" value="二年级"/>二年级
<input type="checkbox" value="三年级"/>三年级
<input type="checkbox" value="四年级"/>四年级
<input type="checkbox" value="五年级"/>五年级
<input type="checkbox" value="六年级"/>六年级
<input type="checkbox" value="七年级"/>七年级
<input type="checkbox" value="八年级"/>八年级
</form>
<form class="button">
<input type="button" value="全选/取消全选" id="all"/>
<input type="button" value="反选" id="Inverse"/>
<input type="button" value="获取选中项" id="get"/>
<br />选中项:<br />
<span id="content"></span>
</form>
.class{
width: 600px;
height: 30px;
}
.button{
overflow: hidden;
}