首页 > 代码库 > 选择表达

选择表达

html<html<head lang="en"<meta charset="UTF-8"<titletitle</head<body<div id="div1"<input type="checkbox"<input type="checkbox"<input type="checkbox"<input type="checkbox"<input type="checkbox"</div<div<input type="button" onclick="selall()" value=http://www.mamicode.com/"全选"<input type="button" onclick="selnone()" value=http://www.mamicode.com/"全不选"<input type="button" onclick="selreverse()" value=http://www.mamicode.com/"反选"</div<scriptfunction selall(){
var div1 = document.getElementById(‘div1‘);
var ins = div1.getElementsByTagName(‘input‘);
for(var i=0; i<ins.length; i++){
if(ins[i].type==‘checkbox‘){
ins[i].checked = true;
}
}
}
function selnone(){
var div1 = document.getElementById(‘div1‘);
var ins = div1.getElementsByTagName(‘input‘);
for(var i=0; i<ins.length; i++){
if(ins[i].type==‘checkbox‘){
ins[i].checked = false;
}
}
}
function selreverse(){
var div1 = document.getElementById(‘div1‘);
var ins = div1.getElementsByTagName(‘input‘);
for(var i=0; i<ins.length; i++){
if(ins[i].type==‘checkbox‘){
ins[i].checked = !ins[i].checked;
}
}
}
script</body</html>

选择表达