代碼如下:
<html>
<head>
<meta http-equiv=content-type content=text/html; charset=gb2312 />
<title>無標題文檔</title>
<script type=text/javascript language=javascript>
function selectalldels()
{
var allcheckboxs = document.getelementsbyname(predelcheck);
var desc = document.getelementbyid(allchecked);
var selectorunselect=false;
for(var i = 0; i < allcheckboxs.length; i ++ )
{
if(allcheckboxs[i].checked){
selectorunselect=true;
break;
}
}
if (selectorunselect)
{
_allunchecked(allcheckboxs);
}else
{
_allchecked(allcheckboxs);
}
}
function _allchecked(allcheckboxs){
for(var i = 0; i < allcheckboxs.length; i ++ )
{
allcheckboxs[i].checked = true;
}
}
function _allunchecked(allcheckboxs){
for(var i = 0; i < allcheckboxs.length; i ++ )
{
allcheckboxs[i].checked = false;
}
}
</script>
</head>
<body>
<p>test</p>
<form>
<input type=checkbox name=predelcheck value=cream>id1
<input type=checkbox name=predelcheck value=sugar >id2
<input type=checkbox name=predelcheck value=sugar>id3
<input type=checkbox name=predelcheck value=sugar>id4
<input type=checkbox name=predelcheck value=sugar>id5
<input type=button id=allchecked value=全選/取消全選 onclick=selectalldels()>
</form>
</body>
</html>
更多信息請查看IT技術專欄