ASP.NET2.0下利用javascript实现TreeView中的checkbox全选 (支持IE/firefox)

1、脚本
function chkAll( treeID)
    {
        //debugger;
        var chkall= document.getElementById("chkall");
        var chkother= document.getElementsByTagName("input");
        for (var i=0;i<chkother.length;i++)
        {
            if( chkother[i].type=='checkbox')
            {
                if(chkother[i].id.indexOf( treeID)>-1)
                {
                    if( chkall.checked==true)
                    {
                        chkother[i].checked=chkall.checked;
                    }
                }
            }
        }
    }

2、添加一个全选按钮
<input id="chkall" type="checkbox" onclick="chkAll(' tvWebSite');" />全选/取消

3、添加一棵树
<asp:TreeView ID=" tvWebSite" runat="server">
   <SelectedNodeStyle BackColor="Silver" ForeColor="White" />
</asp:TreeView>

红色地方为关键地方

你可能感兴趣的:(JavaScript)