<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><번째><input name="allcheck" id="allcheck1" type="checkbox" value="1"/> <br>전체选</th> <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></테이블> <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>체크박스 이름:'record' <br>}; <br>o = $.extend(_defaults,options); <br>_allck=$("#" o.allcheckid); <br>_tbl=_allck .parents("table"); <br>//返回所有选中checkboxid集合 <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>//返回所有选中checkbox的key属性集合 <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>}) <br>return ids.replace(/,$/,'') <br>//返回所有选中checkbox의 문자본集합 <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>//设置所有选中checkbox적id集합 <br>setCheckedIds=function (checkids) { <br>checkids = "," checkids ","; <br>$("input[name=" o.checkboxname "]").each(function() { <br>if (checkids.match("," $(this).val() ",")) <br>$(this).attr("checked","checked") <br>}); <br>} <br>//检查所有checkbox是否全选 <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>{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> </div>