<input type="checkbox" value="1" id="id">编号1
<input type="checkbox" value="2" id="id">编号2
<input type="checkbox" value="3" id="id">编号3
<button id="btnTest" onclick="return t()">testCount</button>
<button id="btnTest" onclick="return showAllChk('id')">showAll</button>
<button id="btnTest" onclick="return myCheckAll('id')">全选ID</button>
<button id="btnTest" onclick="return unCheckAll('id')">全不选ID</button>
<button id="btnTest" onclick="return checkId('id')">检查ID</button>
<input type="checkbox" value="" id ="ALL" name="ALL" onClick = "checkAll('ALL','id')"/><label for="ALL">全选</label>
<script type="text/javascript">
function t(){
alert(document.all.id.length);
}
function showAllChk(chkId)
{
var chkobj = eval("document.all." + chkId);
for(var i=0;i<chkobj.length;i++){
alert(chkobj[i].value);
}
}
function checkAll(allChkId,chkId){
var chkObj = eval("document.all." + chkId);
var chkAllObj = eval("document.all." + allChkId);
for (var i=0;i<chkObj.length;i++){
chkObj[i].checked = chkAllObj.checked;
}
}
function myCheckAll(chkId)
{
var chkobj = eval("document.all." + chkId);
for(var i=0;i<chkobj.length;i++){
chkobj[i].checked = true;
}
}
function unCheckAll(chkId)
{
var chkobj = eval("document.all." + chkId);
for(var i=0;i<chkobj.length;i++){
chkobj[i].checked = false;
}
}
function checkId(chkId)
{
var chkobj = eval("document.all." + chkId);
var result = false;
for(var i=0;i<chkobj.length;i++){
if (chkobj[i].checked){
result = true;
break;
}
}
if (!result){
alert("请至少选一个编号");
chkobj[0].focus();
}
return result;
}
</script>