<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
button{
margin: 0 5px;
}
input{
margin-left: 10px;
}
</style>
</head>
<body>
<button>全选</button>
<button>全不选</button>
<button>反选</button><br>
html:<input type="checkbox" /><br>
css:<input type="checkbox" /><br>
javascript:<input type="checkbox" /><br>
jquery:<input type="checkbox" /><br>
java:<input type="checkbox" /><br>
UI:<input type="checkbox" /><br>
</body>
<script type="text/javascript">
var btn = document.querySelectorAll('button');
var ipt = document.querySelectorAll('input');
btn[0].onclick = function(){
for(var i=0;i<ipt.length;i++){
ipt[i].checked = true;
}
}
btn[1].onclick = function(){
for(var i=0;i<ipt.length;i++){
ipt[i].checked = false;
}
}
btn[2].onclick = function(){
for(var i=0;i<ipt.length;i++){
if(ipt[i].checked){
ipt[i].checked = false;
}else{
ipt[i].checked = true;
}
}
}
</script>
</html>
全选全不选反选案例
最新推荐文章于 2024-09-03 17:02:58 发布