日期:2014-05-18  浏览次数:20434 次

如何使用JS把CheckBoxList中全选?
下面的代码如何应用啊,给小弟一些指点啊,谢谢各位大侠!
<script   language= "javascript ">
function   CheckAllCheckboxes(ownerID,   checked)
{
        var   owner   =   document.getElementById(ownerID);
        if   (!owner   ||   owner.disabled)
                return   false;
       
        var   element;
        var   i   =   0;
        while   (element   =   document.getElementById(ownerID   +   "_ "   +   (i++)))
        {
                if   (!element.disabled)
                        element.checked   =   checked;
        }
       
        return   false;
}
</script>

------解决方案--------------------
<asp:CheckBoxList ID= "chkSetMandatory " runat= "server " CssClass= "tableData " RepeatColumns= "1 "
TabIndex= "9 " RepeatDirection= "Horizontal ">
</asp:CheckBoxList>
<asp:CheckBox ID= "sSelectAll " runat= "server " onclick= "javascript:chkall( 'chkSetMandatory ', 'sSelectAll '); " /> Select/Unselect
All

function chkall(input1,input2)
{
tb = document.getElementById(input1);
tb2 = document.getElementById(input2);
chks = tb.getElementsByTagName( "input ");

if (tb2.checked == true)
{
for (var i=0;i <chks.length;i++)
chks[i].checked = true;
}
else
{
for (var i=0;i <chks.length;i++)
chks[i].checked = false;
}
}