2011-06-20 33 views
0

我正在使用Visual Studio 2008中的jQuery調試ASP.NET 3.5網站上的JavaScript方法。作爲完整性檢查,我想查看按z-index排序的頁面元素列表。什麼是一個很好/簡單的方法來做到這一點?我更喜歡可以輸入到Watch窗口的表達式,但我願意接受其他建議。如何在調試時按z-index對頁面元素進行排序?

編輯:@polarblau回答了我的問題,但我想發佈代碼,我最終在這裏使用它更容易閱讀。下面是我粘貼到監視窗口在Visual Studio:

$.map($('*').sort(function(a, b) { return b.style.zIndex - a.style.zIndex; }), function(e) { return '[' + e.id + '] = [' + e.style.zIndex + ']'; }).join(', ') 

回答

2

會像this工作? -

var sortByZIndex = function(a, b) { 
    return a.style.zIndex - b.style.zIndex; 
} 
var sorted = $('div').sort(sortByZIndex); 
alert("Sorted: " + $.map(sorted, function(e){ return e.id; }).join(', ')); 
+0

謝謝。是的,會的。我把它變成了一個醜陋的一行,並將排序順序改爲遞減順序,但它基本上是一樣的:$ .map($('*')。sort(function(a,b){return b.style.zIndex (','); a.style.zIndex;}),function(e){return'['+ e.id +'] = ['+ e.style.zIndex +']';})。join – FishBasketGordo

相關問題