jquery - 我如何订购 jQuery 包装套装?

标签 jquery

我需要能够获取包装集中最顶层的“.ui-dialog”元素。

我的第一个想法是做这样的事情:

var topDialog = $(".ui-dialog").orderBy("[style*=z-index]").eq(0);

有没有比编写循环来检查值更好的方法?

编辑:只是为了澄清...我需要能够在页面生命周期内的任何给定点获取最顶层的元素(在打开和关闭多个对话框之后)。 Nick Craver 使用 maxZ 变量的答案似乎不起作用,因为删除对话框时该变量不会递减。

这是我现在使用的循环,当我关闭一个对我来说似乎有点丑陋的对话框时:

// Enable printing of the top-most dialog or #page
if ($(".ui-dialog").length > 0) {

    var top = $(".ui-dialog").first();

    $(".ui-dialog").each(function () {
        if ($(this).css("z-index") > top.css("z-index")) {
            top = $(this);
        }
    });

    top.removeClass("dont-print");

} else {

    $("#page").removeClass("dont-print");

}

最佳答案

由于对话框是堆叠的,因此顶部 z-index 的变量实际上是可维护和可访问的,它是:$.ui.dialog.maxZ, you can see how it's set here .

因此,您无需排序,只需查看哪个对话框具有最高索引(只有一个会),如下所示:

var topDialog = $(".ui-dialog").filter(function() { 
                  return $(this).css("z-index") == $.ui.dialog.maxZ;
                });

You can test it out here

关于jquery - 我如何订购 jQuery 包装套装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4299901/

相关文章:

jquery - 使用按钮导航以打开页面(jquery)

javascript - 将 .each 数据写入具有相同 div id 的两个不同类

jquery - 如何让函数强制弹出引导模式?

javascript - 将 td 元素插入到行组中

php - 如何使用 ajax post 和 url 的放大弹出窗口?

javascript - 将 Gridster 插入 WordPress 模板

javascript - 使用 jquery 克隆 primefaces 组件

javascript - 用 jquery 隐藏特定的 sub-div

jquery 跷跷板效果

javascript - 当用户将鼠标悬停在链接上时想要显示图标/选项