前言
提供 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>
<form id="form1">
<input type="checkbox" value='全部選取' onclick='chkall("form1",this)' name=chk><BR>
<input type="checkbox" name="item_001" value="1">1<BR>
<input type="checkbox" name="item_002" value="2">2<BR>
<input type="checkbox" name="item_003" value="3">3<BR>
<input type="checkbox" name="item_003" value="4">4
</form>