Javascript| Tips
Recently do a small project in the company, need to do a multiple-select items Delete function, so write the following JS script examples to achieve, in fact, is often used to compare the basis of things, the master will not have to see.
Program code:
<script language= "JavaScript">
<!--
function CA (frm)
{
var trk=0;
for (Var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name!= ' Allbox ') && (e.type== ')checkbox') && (e.name!= ' Don't want to be selectedcheckbox's name "))
{
trk++;
e.checked=frm.allbox.checked;
frm.del.disabled = frm.allbox.checked?false:true;//Select AllEffect on the disabled property of the Delete button
}
}
}
function CCA (FRM,CB)
{
var tb=to=0;
for (Var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name!= ' Allbox ') && (e.type== ')checkbox') && (e.name!= ' Don't want to be selectedcheckbox's name "))
{
tb++;
if (e.checked)
to++;
}
}
Frm.allbox.checked= (TO==TB) True:false;
if (0==to)//All unchecked and selected, the effect on the disabled property of the Delete button
{
Frm.del.disabled = true;
}
Else
{
frm.del.disabled = false;
}
}
-->
</script>
Call Method:
Select AllThe name of the Allbox is set,onclickEvent execution CA (this.form);
The Checbox of the selected item.onclickEvent execution CCA (this.form,this);