国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery 頁面全選框?qū)嵺`代碼

2019-11-21 00:36:32
字體:
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

<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, "");
}
//設(shè)置所有選中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狀態(tài)
_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'});
//設(shè)置選項(xiàng)allcheckid checkboxname
//取返回值可以調(diào)用checkedIds,checkedKeys,checkedTexts
</script>
</body>
</html>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 黑河市| 措勤县| 怀仁县| 余庆县| 黔西| 衡南县| 车致| 梁山县| 马关县| 安泽县| 金华市| 烟台市| 平度市| 隆安县| 岳阳县| 昌都县| 固始县| 准格尔旗| 都匀市| 义乌市| 平罗县| 清涧县| 祁门县| 青川县| 民勤县| 孟津县| 象州县| 灌阳县| 祁连县| 上高县| 海伦市| 荣昌县| 湘乡市| 中宁县| 麻栗坡县| 博兴县| 噶尔县| 庄浪县| 许昌县| 孝昌县| 隆回县|