我在同一表单(z-index)相关的 jquery-ui 自动完成和滑块方面遇到问题

发布于 2024-09-15 19:25:00 字数 491 浏览 5 评论 0原文

我正在尝试使用 jQuery ui 库创建一个网页。我的设计在表单顶部的输入字段上使用 jQuery ui 自动完成功能。紧邻此自动完成输入表单的下方是一些 jQuery 滑块。问题是,当填充自动完成框时,结果显示在滑块控件的手柄后面。这来自 jQuery 构建滑块的方式,该滑块的 z 索引为 3。jquery 自动完成控件的下拉部分的 z 索引似乎始终设置为 1。我尝试增加 z - 自动完成的输入元素的索引,但这似乎不会影响 jquery 为自动完成下拉列表创建的元素的 z 索引。我还尝试编写自己的 javascript 来按类(它是 ul)获取下拉菜单元素并手动设置它的 z-index。这似乎也不起作用。我假设这意味着,jQuery 代码以某种方式覆盖了我所做的 z-index 更改。这不是浏览器错误,而是 Firefox、Chrome、Safari 和 IE 上的问题。这是 jQuery 给出的下拉框(UL 元素)实际 z-index 的问题。

有人有解决这个问题的办法吗?人们通常如何摆弄 jQuery 自动生成的元素来构建其控件。

I'm attempting to create a web page using the jQuery ui lib. My design uses a jQuery ui autocomplete on an input field at the top of a form. Immediately below this autocomplete input form are some jQuery sliders. The issue is that when the auto complete box populates the results are displayed behind the handle of the slider control. This comes from the way that jQuery builds the sliders which makes pieces of them have a z-index of 3. The z-index of the drop down portion of the jquery autocomplete control appears to always be set to 1. I tried increasing the z-index of the input element that is being auto completed but that doesn't seem effect the z-index of the element jquery creates for the autocomplete drop down. I also tried writing my own javascript to get the drop down menu element by class(it is a ul) and manually set it's z-index. This doesn't seem to work either. I'm assuming this means, somehow the jQuery code is overwriting the z-index change that I'm making. This isn't a browser bug as it is a problem on Firefox, Chrome, Safari and IE. It is a problem with the actual z-index jQuery gives the drop down box (UL element).

Does anyone have a solution to this problem? How does one generally go about fiddling with elements that jQuery automatically generates to build it's controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半葬歌 2024-09-22 19:25:00

使用打开和关闭事件修改 z-index 对我有用:

$( "#tags" ).autocomplete({
  source: availableTags,      
  open: function(event, ui) { $(".ui-slider-handle").css("z-index", -1); },
  close: function(event, ui) { $(".ui-slider-handle").css("z-index", 2); }
});

请参阅此处的演示。

Using the open and close events to modify the z-index worked for me:

$( "#tags" ).autocomplete({
  source: availableTags,      
  open: function(event, ui) { $(".ui-slider-handle").css("z-index", -1); },
  close: function(event, ui) { $(".ui-slider-handle").css("z-index", 2); }
});

See a demo here.

温柔一刀 2024-09-22 19:25:00

根据http://bugs.jqueryui.com/ticket/5238,似乎有2对此的解决方案。

“将 z-index 更改为 3 似乎可以完全解决这个问题。”

您可以在 css 上执行此操作,只需添加“!important”来覆盖库设置的值:

ul.ui-autocomplete {
    z-index: 3 !important;
}

或者“在自动完成输入上设置位置:相对”,以便 .zIndex() 实际上可以计算 z-index。 ”

According to http://bugs.jqueryui.com/ticket/5238, there seem to be 2 solutions for this.

"Changing the z-index to 3 seems to fix this completely."

You can do this on your css, you just need to add "!important" to override the value the library sets:

ul.ui-autocomplete {
    z-index: 3 !important;
}

Or, "set position:relative on autocomplete input, so that .zIndex() can actually compute the z-index."

叶落知秋 2024-09-22 19:25:00

这就是我为自动完成设置 z-index 所做的事情:

$("#myInputId").autocomplete({
    open: function () { $('.ui-autocomplete').css('z-index', 50); },
    source: function (request, response) {
        $.ajax({
            url: "some url",
            type: "POST",
            dataType: "json",
            data: { /* some code... */ },
            success: function (data) { /* some code... */ }
        })
    }
});

This is what I did to set the z-index for autocomplete:

$("#myInputId").autocomplete({
    open: function () { $('.ui-autocomplete').css('z-index', 50); },
    source: function (request, response) {
        $.ajax({
            url: "some url",
            type: "POST",
            dataType: "json",
            data: { /* some code... */ },
            success: function (data) { /* some code... */ }
        })
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文