js反选

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<script>

方法一:
function testCheckbox() {
var check = document.getElementsByName("checkboxid");
for ( var i = 0; i < check.length; i++) {
var e = check[i];
e.checked = !e.checked;
}
}

方法二:

function testCheckbox() {
        var check = document.getElementsByName("checkboxid");
        for ( var i = 0; i < check.length; i++) {
            if (check[i].checked == false) {
                check[i].checked = true;
            } else {
                check[i].checked = false;
            }

        }
    }
</script>
<body>
<form name="checkboxform">
<a href="#" onclick=testCheckbox();>全选/反选</a>
<input type="checkbox" name="checkboxid" value="1" />
<input type="checkbox" name="checkboxid" value="1" />
<input type="checkbox" name="checkboxid" value="1" />
</form>
</body>
</html>

 

你可能感兴趣的:(html,jsp)