<div class="codetitle"> <span><a style="CURSOR: pointer" data="27271" class="copybut" id="copybut27271" onclick="doCopy('code27271')"><u>复制代码</u></a></span>代码如下:</div> <div class="codebody" id="code27271"> <br><html> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>全选</title> <br></head> <br> <br><div>デモ <br><input type="button" onclick="alert(ob.checkedIds());" value="选中ID"/> <br><input type="button" onclick="alert(ob.checkedTexts());" value="选中值"/> <br><input type="button" onclick="alert(ob.checkedKeys('value1'));" value="选中属性值"/> <br> </div> <br><table class="infor"> <br><tr> <br><th><input name="allcheck" id="allcheck1" type="checkbox" value="1"/> <br>全選択 <br></tr><tr> <br><td><input name="record" type="checkbox" value="1" value1="11"/>去<br></td></tr><tr> ; <br><td><input name="record" type="checkbox" value="2" value1="22"/>啊 <br></td></tr><tr> ; <br><td><input name="record" type="checkbox" value="3" value1="33"/>我 <br></td></tr><tr> ; <br><td><input name="record" type="checkbox" value="4" value1="44"/>饿 <br></td></tr> <br></table> <br><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <br><script type="text/javascript" > <br>//http://www.cnblogs.com/libsource <br>(function($){ <br>$.allcheck=function(options){ <br>_defaults = { <br>allcheckid:"allcheck ", <br>checkboxname:'record' <br>}; <br>o = $.extend(_defaults,options); <br>_allck=$("#" o.allcheckid); <br>_tbl=_allck .parents("table"); <br>// すべてのチェックボックスの id 集合を返します <br>checkedIds=function () { <br>var ids = "" <br>$("input[name=" o .checkboxname "]").each(function() { <br>if ($(this).attr("checked")) <br>ids = $(this).val() ","; <br> }); <br>return ids.replace(/,$/,''); <br>} <br>// すべてのチェックボックスのキー属性集合を返す <br>checkedKeys=function (key) { <br> var ids = ""; <br>$("input[name=" o.checkboxname "]").each(function() { <br>if ($(this).attr("checked")) <br>ids = $(this).attr(key) ","; <br>return ids.replace(/,$/,''); <br>} <br>//选中チェックボックスの文本セット <br>checkedTexts=function () { <br>var txts = ""; <br>$("input[name=" o.checkboxname "]").each(function() { <br>if ($(this).attr("checked")) <br>txts = gtrim($(this).parent().text()) "," <br>}); .replace(/,$/,''); <br>} <br>gtrim=function (txt) { <br>return txt.replace(/(^s*)|(s*$)/g, ""); <br>} <br>//すべてのチェックボックスの ID セットを設定します <br>setCheckedIds=function (checkids) { <br>checkids = "," checkids ","; <br>$("input[name=" o.checkboxname "]").each(function() { <br>if (checkids.match("," $(this).val() ",")) <br>$(this).attr("チェック済み","チェック済み") <br>}); <br>} <br>//全チェックボックスの有無全選択 <br>_checkAll=function () { <br>if (this.checked && $("input:checkbox:not([checked]):not(# " o.allcheckid ")", _tbl).length == 0) <br>_allck[0].checked = true; <br>else <br>_allck[0].checked = false; <br>} <br><br>//全选checkbox状態态 <br>_setAllChecked=function () { <br>if (!this.checked) <br>$("input:checkbox", _tbl).removeAttr (「チェック済み」); <br>else <br>$("input:checkbox", _tbl).not(this).attr("checked", "checked"); <br>} <br>_allck.click(_setAllChecked); <br>$("input:checkbox[name=" o.checkboxname "]").each(function(){$(this).click(_checkAll);}); <br>return {checkedIds:checkedIds,checkedKeys:checkedKeys,checkedTexts:checkedTexts,setCheckedIds:setCheckedIds}; <br>}; <br>})(jQuery); <br></script> <br><script type="text/javascript"> <br>var ob=$.allcheck({allcheckid:'allcheck1'}); <br>//配置选项allcheckid checkboxname <br>//取返し值使用可能checkedIds,checkedKeys,checkedTexts <br></script> <br></body> <br></html><br><br> </tr>