zoukankan      html  css  js  c++  java
  • Treeview 父子节点选中的级联操作

          选中父节点,同时选中子节点。 选中子节点,自动勾选上父节点,当所有的子节点都没有选中的时候,又自动取消父节点的勾选。

    代码
       <script src="http://www.cnblogs.com/js/jquery-1.4.2.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(Bind);
            
    function Bind() {
                BindTreeView(
    "tvMenu"truetrue);
            }
            
    function BindTreeView(treeViewId,selectChild,selectParent) {

                $(
    "#" + treeViewId + " input").click(function() {
                    
    if (selectChild) {
                        
    var divItem = $(this).parent().parent().parent().parent().next();
                        
    if (divItem[0!= null){ // 屏蔽选最后一个时,会弹出错误的漏洞
                            if (divItem[0].tagName == "DIV")
                                divItem.find(
    "input").attr("checked", $(this).get(0).checked); 
                        }
                    }
                    
    if (selectParent) {
                        SelectParentNode(treeViewId, $(
    this));
                    }
                });
            }

            
    function SelectParentNode(treeViewId,node) {
                
    if (node.get(0!= null ){
                    
    if (node.get(0).checked == true) {
                        
    var pdiv = node.parent().parent().parent().parent().parent();
                        
    if (pdiv.get(0).id != treeViewId) {
                            
                            pdiv.prev().find(
    "input").attr("checked", node.get(0).checked);

                            SelectParentNode(treeViewId, pdiv.prev().find(
    "input"));
                        }
                    } 
    else { // 取消所有子的选择,父节点也取消
                        var pdiv = node.parent().parent().parent().parent().parent();
                        
    if (pdiv.get(0).id != treeViewId) {

                            
    var divItem = node.parent().parent().parent().parent().parent();
                            
    if (divItem[0!= null) {
                                
    if (divItem[0].tagName == "DIV") {
                                    
    if (divItem.find("input[type='checkbox']:checked").size() == 0 ) {
                                        pdiv.prev().find(
    "input").attr("checked"false);
                                    }
                                }
                            }

                            SelectParentNode(treeViewId, pdiv.prev().find(
    "input"));
                        }
                    }
                }
            }
        
    </script>

    走向地狱的途中,不小心走了程序员这条路,路上一个个黑心的老板,和暗无天日的加班,我才发现,通往地狱的路径中,我们这行是最短的。

  • 相关阅读:
    草稿~!
    Jmeter使用:JSON返回数据处理
    Jmeter使用:操作MySQL
    jmeter+ant+jenkins 搭建接口自动化测试环境
    【未完成】Jmeter接口自动化测试:参数化设置
    RDLC报表系列(六) 多图表-折线图和柱状图
    RDLC报表系列(五) 简单的图表-柱状图
    RDLC报表系列(四) 矩阵
    流程图里的形状符号的含义及意义(转 )
    Login failed for user 'NT AUTHORITYNETWORK SERVICE'的解决方法
  • 原文地址:https://www.cnblogs.com/zlfucku/p/1687823.html
Copyright © 2011-2022 走看看