复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>全选</title>
</head>
<body>
<div>demo
<input type="button" onclick="alert(ob.checkedIds());" value="选中ID"/>
<input type="button" onclick="alert(ob.checkedTexts());" value="选中值"/>
<input type="button" onclick="alert(ob.checkedKeys('value1'));" value="选中属性值"/>
</div>
<table class="infor">
<tr>
<th><input name="allcheck" id="allcheck1" type="checkbox" value="1"/>
全选</th>
</tr><tr>
<td><input name="record" type="checkbox" value="1" value1="11"/>去
</td></tr><tr>
<td><input name="record" type="checkbox" value="2" value1="22"/>啊
</td></tr><tr>
<td><input name="record" type="checkbox" value="3" value1="33"/>我
</td></tr><tr>
<td><input name="record" type="checkbox" value="4" value1="44"/>饿
</td></tr>
</table>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js"><script type="text/javascript" >
//http://www.cnblogs.com/libsource
(function($){
$.allcheck=function(options){
_defaults = {
allcheckid:"allcheck",
checkboxname:'record'
};
o = $.extend(_defaults,options);
_allck=$("#"+o.allcheckid);
_tbl=_allck.parents("table");
//返回所有选中checkbox的id集合
checkedIds=function () {
var ids = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
ids += $(this).val() + ",";
});
return ids.replace(/,$/,'');
}
//返回所有选中checkbox的key属性集合
checkedKeys=function (key) {
var ids = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
ids += $(this).attr(key) + ",";
});
return ids.replace(/,$/,'');
}
//返回所有选中checkbox的文本集合
checkedTexts=function () {
var txts = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
txts += gtrim($(this).parent().text()) + ",";
});
return txts.replace(/,$/,'');
}
gtrim=function (txt) {
return txt.replace(/(^\s*)|(\s*$)/g, "");
}
//设置所有选中checkbox的id集合
setCheckedIds=function (checkids) {
checkids = ","+checkids+",";
$("input[name=" + o.checkboxname + "]").each(function() {
if (checkids.match(","+$(this).val()+","))
$(this).attr("checked","checked");
});
}
//检查所有checkbox是否全选
_checkAll=function () {
if (this.checked && $("input:checkbox:not([checked]):not(#" + o.allcheckid + ")", _tbl).length == 0)
_allck[0].checked = true;
else
_allck[0].checked = false;
}
//全选checkbox状态
_setAllChecked=function () {
if (!this.checked)
$("input:checkbox", _tbl).removeAttr("checked");
else
$("input:checkbox", _tbl).not(this).attr("checked", "checked");
}
_allck.click(_setAllChecked);
$("input:checkbox[name="+o.checkboxname+"]").each(function(){$(this).click(_checkAll);});
return {checkedIds:checkedIds,checkedKeys:checkedKeys,checkedTexts:checkedTexts,setCheckedIds:setCheckedIds};
};
})(jQuery);
</script>
<script type="text/javascript">
var ob=$.allcheck({allcheckid:'allcheck1'});
//设置选项allcheckid checkboxname
//取返回值可以调用checkedIds,checkedKeys,checkedTexts
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>全选</title>
</head>
<body>
<div>demo
<input type="button" onclick="alert(ob.checkedIds());" value="选中ID"/>
<input type="button" onclick="alert(ob.checkedTexts());" value="选中值"/>
<input type="button" onclick="alert(ob.checkedKeys('value1'));" value="选中属性值"/>
</div>
<table class="infor">
<tr>
<th><input name="allcheck" id="allcheck1" type="checkbox" value="1"/>
全选</th>
</tr><tr>
<td><input name="record" type="checkbox" value="1" value1="11"/>去
</td></tr><tr>
<td><input name="record" type="checkbox" value="2" value1="22"/>啊
</td></tr><tr>
<td><input name="record" type="checkbox" value="3" value1="33"/>我
</td></tr><tr>
<td><input name="record" type="checkbox" value="4" value1="44"/>饿
</td></tr>
</table>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js"><script type="text/javascript" >
//http://www.cnblogs.com/libsource
(function($){
$.allcheck=function(options){
_defaults = {
allcheckid:"allcheck",
checkboxname:'record'
};
o = $.extend(_defaults,options);
_allck=$("#"+o.allcheckid);
_tbl=_allck.parents("table");
//返回所有选中checkbox的id集合
checkedIds=function () {
var ids = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
ids += $(this).val() + ",";
});
return ids.replace(/,$/,'');
}
//返回所有选中checkbox的key属性集合
checkedKeys=function (key) {
var ids = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
ids += $(this).attr(key) + ",";
});
return ids.replace(/,$/,'');
}
//返回所有选中checkbox的文本集合
checkedTexts=function () {
var txts = "";
$("input[name=" + o.checkboxname + "]").each(function() {
if ($(this).attr("checked"))
txts += gtrim($(this).parent().text()) + ",";
});
return txts.replace(/,$/,'');
}
gtrim=function (txt) {
return txt.replace(/(^\s*)|(\s*$)/g, "");
}
//设置所有选中checkbox的id集合
setCheckedIds=function (checkids) {
checkids = ","+checkids+",";
$("input[name=" + o.checkboxname + "]").each(function() {
if (checkids.match(","+$(this).val()+","))
$(this).attr("checked","checked");
});
}
//检查所有checkbox是否全选
_checkAll=function () {
if (this.checked && $("input:checkbox:not([checked]):not(#" + o.allcheckid + ")", _tbl).length == 0)
_allck[0].checked = true;
else
_allck[0].checked = false;
}
//全选checkbox状态
_setAllChecked=function () {
if (!this.checked)
$("input:checkbox", _tbl).removeAttr("checked");
else
$("input:checkbox", _tbl).not(this).attr("checked", "checked");
}
_allck.click(_setAllChecked);
$("input:checkbox[name="+o.checkboxname+"]").each(function(){$(this).click(_checkAll);});
return {checkedIds:checkedIds,checkedKeys:checkedKeys,checkedTexts:checkedTexts,setCheckedIds:setCheckedIds};
};
})(jQuery);
</script>
<script type="text/javascript">
var ob=$.allcheck({allcheckid:'allcheck1'});
//设置选项allcheckid checkboxname
//取返回值可以调用checkedIds,checkedKeys,checkedTexts
</script>
</body>
</html>
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月30日
2024年09月30日
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】