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>

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

  • 相关阅读:
    分享免费的jQuery Mobile Wordpress主题 jQMobile
    分享50个使用非比寻常导航菜单设计的创意网站
    分享一个超酷javascript全屏幻灯导航(fullscreen slide navigation)
    分享一款jQuery的UI插件:Ninja UI
    使用jQuery开发一个超酷的倒计时效果
    分享使用jQuery和CSS实现的一个超酷缩略图悬浮逼近效果
    Nosql数据库教程之初探MongoDB 第一部分
    分享一个使一行文字变形产生弯曲弧度特效的jQuery插件 Arctext.js
    分享2011年12月的11个最棒的jQuery插件
    分享8个最新的javascript脚本资源
  • 原文地址:https://www.cnblogs.com/zlfucku/p/1687823.html
Copyright © 2011-2022 走看看