当前位置:编程学习 > JAVA >>

全选和反选

效果:
代码如下:
<!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>
 
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,