  
- 積分
- 7435
- 經驗值
- 7929 EXP
- 家電幣
- 673822 法拉
- H值
- 8384 汁
- 熱血
- 6000 度
- 嘴砲
- 3266 值
         
|
第一種:勾選checkbox才能全選
<script language="JavaScript">
function chkall(input1,input2)
{
var objForm = document.forms[input1];
var objLen = objForm.length;
for (var iCount = 0; iCount < objLen; iCount++)
{
if (input2.checked == true)
{
if (objForm.elements[iCount].type == "checkbox")
{
objForm.elements[iCount].checked = true;
}
}
else
{
if (objForm.elements[iCount].type == "checkbox")
{
objForm.elements[iCount].checked = false;
}
}
}
}
</script>
<input value="全部選取" onclick='chkall("form1",this)' name="chk" type="checkbox">
<input name="c1" value="1" type="checkbox">1<br>
<input name="c2" value="1" type="checkbox">2<br>
<input name="c3" value="1" type="checkbox">3<br>
<input name="c4" value="1" type="checkbox">4<br>
<input name="c5" value="1" type="checkbox">5<br> 第二種:全選,取消,反向選取都分開按(就跟yahoo的信箱全選是一樣的)
<script language="JavaScript">
function selAll(){
<font color="SeaGreen">//變數checkItem為checkbox的集合</font>
var checkItem = document.getElementsByName("c1");
for(var i=0;i<checkitem.length;i++){ checkitem<i="">.checked=true;
}
}
function unselAll() {
<font color="SeaGreen">//變數checkItem為checkbox的集合</font>
var checkItem = document.getElementsByName("c1");
for(var i=0;i<checkitem.length;i++){ checkitem<i="">.checked=false;
}
}
function usel() {
<font color="SeaGreen">//變數checkItem為checkbox的集合</font>
var checkItem = document.getElementsByName("c1");
for(var i=0;i<checkitem.length;i++){ checkitem<i="">.checked=!checkItem<i>.checked;
}
}
</script>
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<input name="c1" type="checkbox">
<br>
<input value="全選" onclick="selAll();" type="button">
<input value="全取消" onclick="unselAll();" type="button">
<input value="反向選取" onclick="usel();" type="button"> |
|