2013-04-15 88 views
1

我想要顯示一個.folder,當它點擊並隱藏所有其他內容時。就像一個文件瀏覽器。顯示小孩並隱藏父母

+0

我能問你爲什麼不能簡單地用一個文件瀏覽器?如果您正在與用戶的硬盤進行交互,則應該有可用的IO類來顯示簡單的文件瀏覽器。 – Jeff

+0

根本不與用戶的硬盤進行交互。從服務器端列出文件。 – Kivylius

+0

http://jsfiddle.net/什麼不工作? – DerStoffel

回答

0
$('ul li.folder').on('click',function(e){ 

    $(this).siblings('li').toggle(); 
    $(this).children().toggle(); 
    e.stopPropagation(); 
}); 

這應該工作。

1

你可以嘗試使用jQuery siblings() selector.

$('.folder').on('click',function(e){ 
    $(this).children().toggle(); 
    $(this).siblings('li.folder').children().toggle(); 
    e.stopPropagation(); 
}); 
+0

這幾乎完美,但不適用於2/3/4 ..級別深的列表 – Kivylius

+0

玩它。也許你需要使用一些其他選擇器(.parent()?.children()?你看到的那種行爲是不是有意的?嘗試一下,這很有趣。 – Jeff

0

Sample

//toggle children and siblings 
$('.folder').on('click',function(e){ 
    $(this).children().toggle(); 
    $(this).siblings().toggle(); 
    e.stopPropagation(); 
}); 
//cancel file clicks 
$('.file').on('click', function(e) { 
    e.stopPropagation(); 
    return false; 
});