I'm having trouble with jquery-ui autocomplete and slider on the same form (z-index) related

被刻印的时光 ゝ 提交于 2019-12-01 20:28:48

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.

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."

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... */ }
        })
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!