jquery 全选 全不选 事件绑定
<td width="82%" colspan="3"> <input type="checkbox" id="all">全选<input type="checkbox" id="reverse">反选 </td> <td width="82%" colspan="3"> <s:checkboxlist name="resUuids" list="resList" listKey="uuid" listValue="name"></s:checkboxlist> </td> $(function(){ $("#all").click(function(){ var flag = $(this).attr("checked"); $("[name=resUuids]").attr("checked",flag == "checked"); }); $("#reverse").click(function(){ $("[name=resUuids]").each(function(){ var flag = $(this).attr("checked"); $(this).attr("checked", !(flag =="checked")); }); checkSelect(); }); $("[name=resUuids]").click(function(){ checkSelect(); }); function checkSelect(){ var allFlag = true; $("[name=resUuids]").each(function(){ var flag = $(this).attr("checked") == "checked"; allFlag = allFlag && flag; }); $("#all").attr("checked",allFlag); } });