JS加强总结第二天(实现select的全选和反选不选的操作 案例)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>js_nameNode.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
window.onload = function() {
//根据id获取 全选,全不选 反选的节点对象
var qx = document.getElementById("qx");
var fx = document.getElementById("fx");
var qbx = document.getElementById("qbx");
//注册事件
qx.onclick = test;
fx.onclick = test;
qbx.onclick = test;
}
function test(value) {
//获取name="fav"的所有节点对象
var favs = document.getElementsByName("fav");
for ( var i = 0; i < favs.length; i++) {
var fav = favs[i];
switch (value) {
case 1:
fav.checked = true;
break; //break语句只是跳出switch语句块 并没有跳出for循环
case 2:
fav.checked = !fav.checked;
break;
case 0:
fav.checked = false;
break;
}
}
}
function test2() {
//获取name="fav"的所有节点对象
var favs = document.getElementsByName("fav");
for ( var i = 0; i < favs.length; i++) {
var fav = favs[i];
switch (this.value) {
case '1':
fav.checked = true;
break; //break语句只是跳出switch语句块 并没有跳出for循环
case '2':
fav.checked = !fav.checked;
break;
case '0':
fav.checked = false;
break;
}
}
}
function test1() {
//获取name="fav"的所有节点对象
var favs = document.getElementsByName("fav");
switch (this.value) {
case '1':