checkbox的全选和返选

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type ="text/javascript">
window.onload = function () {
var bt = document.getElementById("btn");
bt.onclick = function() {
var cbs = document.getElementsByName("che");
for (var i = 0; i < cbs.length; i++) {

if(cbs[i].type=="checkbox"){//判断是否是checkbox
cbs[i].checked = !cbs[i].checked;

}
}
}
}
</script>
</head>
<body>
<input type ="button" id="btn" value ="test"/>
<input type ="checkbox" name ="che"/><input type ="checkbox" name ="che"/><input type ="checkbox" name ="che"/>
</body>
</html>

posted @ 2014-10-12 10:46  xjt360  阅读(146)  评论(0编辑  收藏  举报