首页 / JQUERY / jquery 页面全选框实践代码
jquery 页面全选框实践代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jquery 页面全选框实践代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3047字,纯文字阅读大概需要5分钟。
内容图文
![jquery 页面全选框实践代码](/upload/InfoBanner/zyjiaocheng/372/35ec3503ccb04fd6bd3e0cc98f8d3f3b.jpg)
<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="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<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>
内容总结
以上是互联网集市为您收集整理的jquery 页面全选框实践代码全部内容,希望文章能够帮你解决jquery 页面全选框实践代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。