见如下代码:
function getMaxZIndex() {
var maxZ = Math.max.apply(null,
$.map($('body *'), function(e,n) {
if ($(e).css('position') != 'static')
return parseInt($(e).css('z-index')) || -1;
}));
return maxZ;
}
这里要说明下, 如果一个元素未设置z-index
值, 那么将会取到auto
.
如果不用jQuery, 也可考虑使用document.all || document.querySelectorAll("*")
来获取所有元素,
使用window.getComputedStyle(ele, null).zIndex
来获取元素的z-index
值.
欢迎补充指正!