电竞比分网-中国电竞赛事及体育赛事平台

分享

asp.net的Treeview怎么實(shí)現(xiàn)父節(jié)點(diǎn)選中子結(jié)點(diǎn)全部選中

 實(shí)力決定地位 2010-06-05
1.這是js代碼
<script type="text/javascript">
         function Davidovitz_HandleCheckbox() {
            var element = event.srcElement;
            if (element.tagName == "INPUT" && element.type == "checkbox") {
                var checkedState = element.checked;
                while (element.tagName != "TABLE") // Get wrapping table
                {
                    element = element.parentElement;
                }
 
                Davidovitz_UnCheckParents(element); // Uncheck all parents
 
                element = element.nextSibling;
 
                if (element == null) // If no childrens than exit
                    return;
 
                var childTables = element.getElementsByTagName("TABLE");
                for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++) {
                    Davidovitz_CheckTable(childTables[tableIndex], checkedState);
                }
            }
        }
 
        // Uncheck the parents of the given table, Can remove the recurse (redundant)
        function Davidovitz_UnCheckParents(table) {
            if (table == null || table.rows[0].cells.length == 2) // This is the root
            {
                return;
            }
            var parentTable = table.parentElement.previousSibling;
            Davidovitz_CheckTable(parentTable, false);
            Davidovitz_UnCheckParents(parentTable);
        }
 
        // Handle the set of checkbox checked state
        function Davidovitz_CheckTable(table, checked) {
            var checkboxIndex = table.rows[0].cells.length - 1;
            var cell = table.rows[0].cells[checkboxIndex];
            var checkboxes = cell.getElementsByTagName("INPUT");
            if (checkboxes.length == 1) {
                checkboxes[0].checked = checked;
            }
        }
    </script>
2.在page_load事件里加這么一句話進(jìn)行注冊事件
TreeView1.Attributes.Add("onclick", "Davidovitz_HandleCheckbox()");
就可以完全實(shí)現(xiàn)父節(jié)點(diǎn)選中而是實(shí)現(xiàn)子節(jié)點(diǎn)所有被選中
 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多