---
title: "全选,全不选,反选.等等等等"
author: "alive41"
date: "2011-12-30T11:12:45Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2011-12-30T11:12:45Z"
id: 1330067
url: "https://alive41.iteye.com/blog/1330067"
---

\[code="js"]

全 选  
反 选  
Item1  
Item2  
Item3  
Item4  
Item5

\[/code] \[code="js"] 全选 反选  
篮球  
旅游  
读书  
美食  
睡觉 \[/code] \[code="js"]

全 选  
反 选  
Item1  
Item2  
Item3  
Item4  
Item5

\[/code] \[code="js"]var checkFlag = true;　　　　 function ChooseAll() { if (checkFlag) {　　　　　　　　 var inputs = document.all.tags("INPUT");　　　　　　　　 for (var i = 0; i &lt; inputs.length; i++) {　　　　　　　　　　 if (inputs\[i].type == "checkbox" && inputs\[i].id != "CheckAll") { inputs\[i].checked = true;　　　　　　　　　　 }　　　　　　　　 } checkFlag = false;　　　　　　 } else {　　　　　　　　 var inputs = document.all.tags("INPUT");　　　　　　　　 for (var i = 0; i &lt; inputs.length; i++) {　　　　　　　　　　 if (inputs\[i].type == "checkbox" && inputs\[i].id != "CheckAll") { inputs\[i].checked = false;　　　　　　　　　　 }　　　　　　　　 } checkFlag = true;　　　　　　 }　　　　 }\[/code] \[code="js"] 测试测试  
\[/code]