jquery - 如何找到文档中最高的 z-index,无论它们是什么标签?

标签 jquery z-index jquery-1.9

如何找到文档中最高的 z-index,无论它们是什么标签?

我找到了这段代码,但我测试了它,但它不起作用,

//include jQuery.js --  visit: http://jquery.com/
$(function(){
    var maxZ = Math.max.apply(null,$.map($('body > *'), function(e,n){
           if($(e).css('position')=='absolute')
                return parseInt($(e).css('z-index'))||1 ;
           })
    );
    alert(maxZ);
});

有更好的方法来做到这一点吗?

编辑:

如果我将代码更改为这样,似乎可以工作,

$('body *')

$('body > *') --> is for div only I guess.

最佳答案

这不是最有效的解决方案,但它应该可行。 jsFiddle .

请注意,您必须指定一个位置,以便 z-index 返回值。

var highest = -999;

$("*").each(function() {
    var current = parseInt($(this).css("z-index"), 10);
    if(current && highest < current) highest = current;
});

alert(highest);

关于jquery - 如何找到文档中最高的 z-index,无论它们是什么标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17686544/

相关文章:

java - jquery 移动 android t9 禁用

jquery - Internet Explorer 中的 Markdown 失败

jquery - Noty jQuery 插件确认按钮

javascript - Blueimp 文件上传插件只上传一次

javascript - 多选列表在单击时移动鼠标时取消选择所有选择

javascript - 需要帮助/Off-Canvas Flexbox 菜单切换/z-index

html - 具有 :before - unexpected background behaviour/stacking order 的 CSS 等高列

css - 使 div 内的图像显示在其 div 背景后面

javascript - jquery:如何选择属性名称中包含数组值的复选框?

jquery:删除指针光标?