html中的js全选/取消全选操作示例代码
2014-11-20来源:易贤网

代码如下:

<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技术专栏

推荐信息