日期:2014-05-16 浏览次数:20386 次
<html>
<head>
?<title>js全选简单例子</title>
?<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
?<meta http-equiv="Cache-Control" content="no-store" />
?<meta http-equiv="Pragma" content="no-cache" />
?<meta http-equiv="Expires" content="0" />
<script type="text/javascript">
function selectAll(obj,list) {
??? if(!(obj && list)) {
???? return;
??? }
??? if(list.length)
??? {
??? ??? for(var i=0;i<list.length;i++)
??? ??? {
??? ??? ??? list[i].checked=obj.checked;
??? ??? }
??? }
??? else
??? {
??? ??? list.checked=obj.checked;
??? }
}
?
?</script>
</head>
<body>
?????
??????? <table >
?????????
?????????? <tr>
?????????????? <td >全选<input type="checkbox" onclick="selectAll(this,document.all('form1').id)"></td>
?????????????? <td >水果种类</td>
?????????? </tr>
?????????? <form name="form1" >
????
???? <tr? >
??????????? <td ><input type="checkbox" name="id" value="1"></td>
??????????? <td>苹果</td>
?????????? </tr>
????
???? <tr? >
??????????? <td ><input type="checkbox" name="id" value="2"></td>
??????????? <td>橘子</td>
?????????? </tr>
????
???? <tr? >
??????????? <td ><input type="checkbox" name="id" value="3"></td>
??????????? <td>梨子</td>
?????????? </tr>
????
???? <tr? >
??????????? <td ><input type="checkbox" name="id" value="4"></td>
??????????? <td>香蕉</td>
?????????? </tr>
????
???? <tr >
??????????? <td ><input type="checkbox" name="id" value="5"></td>
??????????? <td>荔枝</td>
?????????? </tr>
????
???? </form>
??????? </table>
???????
</body>
</html>