用JS中全选或者是全不选

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'checkbox.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css"> --> </head> <mce:script type="text/javascript"><!-- function checkAllFruit() { var objs = document.getElementsByTagName("input"); for(var i=0;i<objs.length;i++) { if(objs[i].type == "checkbox") { objs[i].checked = true; } } } function unCheckAllFruit() { var objs = document.getElementsByTagName("input"); for(var i=0;i<objs.length;i++) { if(objs[i].type == "checkbox") { objs[i].checked = false; } } } // --></mce:script> <body> <form action="" id="form1"> <b>水果(checkbox同名):</b> <br> <input type="checkbox" name="fruit" value="1"/> 苹果 <br> <input type="checkbox" name="fruit" value="2"/> 梨 <br> <input type="checkbox" name="fruit" value="3"/> 桃 <br> <input type="button" name="Submit" value="全选" onclick="checkAllFruit()" /> <input type="button" name="Submit" value="全部取消" onclick="unCheckAllFruit()" /> <br> </form> </body> </html>

你可能感兴趣的:(function,String,input,Path,button,stylesheet)