当前位置: 代码迷 >> Web前端 >> 全选跟反选
  详细解决方案

全选跟反选

热度:35   发布时间:2013-03-01 18:33:02.0
全选和反选

效果:


代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
window.onload = function(){
var oSelsctAll = document.getElementById("selectAll");
var oFx = document.getElementById("fx");
var aInput = document.getElementsByTagName("input");
oSelsctAll.onclick = function(){
for(var i = 0;i<aInput.length;i++){
if(aInput[i].checked == true){
aInput[i].checked = false;
}else{
aInput[i].checked = true;
}

}
}
oFx.onclick = function(){
for(var i = 0;i<aInput.length;i++){
aInput[i].checked = !aInput[i].checked;//“!”为非
}
}
}
</script>
<title>无标题文档</title>


</head>


<body>
<button id="selectAll">全选</button><br />
<button id="fx">反选</button><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
</body>
</html>


  相关解决方案