澳门皇冠金沙网站-澳门皇冠844网站

热门关键词: 澳门皇冠金沙网站,澳门皇冠844网站

通过js来制作复选框的全选和不选效果,页面全选

复制代码 代码如下:

复制代码 代码如下:

<html>
<head>
<title>制作全选效果</title>
<script language="javascript">
function selectAll(){
allcheckBoxs=document.getElementsByName("a");
var a2=document.getElementsByName("a1");
if(a2[0].checked){
for(var i=0;i<allcheckBoxs.length;i ){
allcheckBoxs[i].checked = true;
}
}else{
for(var i=0;i<allcheckBoxs.length;i ){
allcheckBoxs[i].checked = false;
}
}
}
</script>
</head>
<body>
<form name="myform">
<table>
<tr><td colspan="2"><img src="images/head.jpg"/></td></tr>
<tr>
<td><input type="checkbox" name="a1" onclick="selectAll()" />全选/全不选</td>
<td> <img src="images/top.jpg"/></td>
</tr>
<tr><td><input type="checkbox" name="a" /></td><td><img src="images/one.jpg"/></td></tr>
<tr><td><input type="checkbox" name="a" /></td><td><img src="images/two.jpg"/></td></tr>
<tr><td><input type="checkbox" name="a" /></td><td><img src="images/three.jpg"/></td></tr>
<tr><td><input type="checkbox" name="a" /></td><td><img src="images/four.jpg"/></td></tr>
</table>
</form>
</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=";
<script type="text/javascript" >
//
(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;
}

本文由澳门皇冠金沙网站发布于前端开发,转载请注明出处:通过js来制作复选框的全选和不选效果,页面全选