<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-348  評論-598  文章-0  trackbacks-0

    下面的代碼是,當選中父節點,則子節點全選;選中任意一個子節點,則選中父節點

    jQuery.noConflict();//與JSF搭配需要這句話,不然會有沖突
            jQuery(document).ready(function() {
            
    // Add click event listener to each checkbox in the tree page
            // Note! Using this simple selector assumes that there are no other 
            // checkboxes on the page, if there are other checkboxes then
            // selector should be changed    
                jQuery(":checkbox").click(function(){
                    updateChildren(
    this);
                    updateParent(
    this);
                 }
    );
            }
    );
            
    </script>
            
    <script type="text/javascript">
            
    function updateChildren(currentCheckBox)
            
    {
                
    // Get state of current checkbox (true or false)
                var state = currentCheckBox.checked;
                
                
    // Get parent TABLE, where current checkbox is places
                var parentTables = jQuery(currentCheckBox).parents("table"); 
                
    var parentTable = parentTables[0];    
            
                
    // Get DIV where child nodes with checkboxes are situated
                // See http://docs.jquery.com/Traversing/ to get better uderstanding of
                // parents() and next()        
                var childDivs = jQuery(parentTable).next("div");    
                
    if(    childDivs.length > 0 )
                
    {
                    
    var childDiv = childDivs[0];        
                
                    
    // Iterate over all child nodes checkboxes and set same state as the 
                    // current checkbox state
                    jQuery(childDiv).contents().find(":checkbox").each(function() {
                        
    this.checked = state;
                    }
    );
                }


            }

            
            
    //更新父節點的方法,如果子節點全部選中則父節點選中,如果子節點中有一個選中,則父節點也選中
            function updateParent(currentCheckbox) {
                
    var parentDivs = jQuery(currentCheckbox).parents("div");
                
    var parentDiv = parentDivs[0];    

                
    var hasSelected = false;
                
                jQuery(parentDiv).contents().find(
    ":checkbox").each(function() {
                    
    if(this.checked) {
                        hasSelected 
    = true;
                    }

                }
    );
                
                
    var parentTables = jQuery(parentDiv).prev("table");
                
    if(parentTables.length > 0)
                
    {
                    
    var parentTable = parentTables[0];
                
                    
    var parentCheckboxes = jQuery(parentTable).find(":checkbox");
                    
    var parentCheckbox = parentCheckboxes[0];
                    
                    parentCheckbox.checked 
    = hasSelected ;
                }


            }

    下面的代碼是,當選中父節點,則子節點全選;選中所有子節點,則選中父節點
    jQuery.noConflict();//與JSF搭配需要這句話,不然會有沖突
            jQuery(document).ready(function() {
            
    // Add click event listener to each checkbox in the tree page
            // Note! Using this simple selector assumes that there are no other 
            // checkboxes on the page, if there are other checkboxes then
            // selector should be changed    
                jQuery(":checkbox").click(function(){
                    updateChildren(
    this);
                    updateParent(
    this);
                 }
    );
            }
    );
            
    </script>
            
    <script type="text/javascript">
            
    function updateChildren(currentCheckBox)
            
    {
                
    // Get state of current checkbox (true or false)
                var state = currentCheckBox.checked;
                
                
    // Get parent TABLE, where current checkbox is places
                var parentTables = jQuery(currentCheckBox).parents("table"); 
                
    var parentTable = parentTables[0];    
            
                
    // Get DIV where child nodes with checkboxes are situated
                // See http://docs.jquery.com/Traversing/ to get better uderstanding of
                // parents() and next()        
                var childDivs = jQuery(parentTable).next("div");    
                
    if(    childDivs.length > 0 )
                
    {
                    
    var childDiv = childDivs[0];        
                
                    
    // Iterate over all child nodes checkboxes and set same state as the 
                    // current checkbox state
                    jQuery(childDiv).contents().find(":checkbox").each(function() {
                        
    this.checked = state;
                    }
    );
                }


            }

            
            
    //更新父節點的方法,如果子節點全部選中則父節點選中,如果子節點中有一個未選中,則父節點也未選中
            function updateParent(currentCheckbox) {
                
    var parentDivs = jQuery(currentCheckbox).parents("div");
                
    var parentDiv = parentDivs[0];    

                
    var hasSelected = true;
                
                jQuery(parentDiv).contents().find(
    ":checkbox").each(function() {
                    
    if(!this.checked) {
                        hasSelected 
    = false;
                    }

                }
    );
                
                
    var parentTables = jQuery(parentDiv).prev("table");
                
    if(parentTables.length > 0)
                
    {
                    
    var parentTable = parentTables[0];
                
                    
    var parentCheckboxes = jQuery(parentTable).find(":checkbox");
                    
    var parentCheckbox = parentCheckboxes[0];
                    
                    parentCheckbox.checked 
    = hasSelected ;
                }


            }


    ---------------------------------------------------------
    專注移動開發

    Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
    posted on 2009-12-27 22:52 TiGERTiAN 閱讀(2760) 評論(0)  編輯  收藏 所屬分類: JavaJSF
    主站蜘蛛池模板: 亚美影视免费在线观看| 亚洲丁香婷婷综合久久| a毛片免费在线观看| 亚洲精品美女久久久久99小说| 色噜噜噜噜亚洲第一| 日韩视频免费一区二区三区| 亚洲AV无码AV日韩AV网站| 在线观看人成视频免费| 国产91成人精品亚洲精品| 亚洲av日韩片在线观看| 在线免费视频你懂的| 亚洲国产成人久久精品动漫| 久久久久久夜精品精品免费啦| 亚洲一区精品中文字幕| 久久午夜免费视频| 亚洲精品乱码久久久久蜜桃 | 美女被暴羞羞免费视频| 亚洲电影日韩精品| 中文字幕乱理片免费完整的| 亚洲国产高清在线| 嫩草影院在线免费观看| 日韩免费高清一级毛片| 亚洲AV无码一区二区二三区入口| 国内精品免费麻豆网站91麻豆| 学生妹亚洲一区二区| 免费成人黄色大片| 日本免费久久久久久久网站| 亚洲AV无码精品蜜桃| 日本中文一区二区三区亚洲| a级成人毛片免费图片| 亚洲偷自精品三十六区| 亚洲av日韩av欧v在线天堂| 无码人妻一区二区三区免费看 | 久久亚洲色WWW成人欧美| 亚洲午夜福利717| 91免费资源网站入口| japanese色国产在线看免费| 亚洲欧洲精品久久| 国产裸模视频免费区无码| 精品国产污污免费网站 | 一级黄色免费毛片|