在 JQ UI 版本 1.8.6 中,Jquery UI 自动完成附加到正文而不是给定对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4375513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery UI Autocomplete appends to body rather than the given object in JQ UI Version 1.8.6
提问by Blowsie
Ive been using jquery auto-completes on my web page for a while , but after updating jquery ui to version 1.8.6 from 1.8rc3 , the autocomplete ul object is now appended to the body rather than directly after the given selector.
我已经在我的网页上使用 jquery 自动完成有一段时间了,但是在将 jquery ui 从 1.8rc3 更新到版本 1.8.6 之后,自动完成 ul 对象现在附加到正文而不是直接在给定的选择器之后。
The code below is not valid of course, it just highlights the problem im having.
下面的代码当然无效,它只是突出了我遇到的问题。
In 1.8rc3
在 1.8rc3
$("#myinput").autocomplete(.....
<input id="myinput"/>
<ul id="autocomplete"></ul>
<div>Loads of other content</div>
<div>Loads of other content</div>
<div>Loads of other content</div>
</body>
In 1.8.6
在 1.8.6
$("#myinput").autocomplete(.....
<input id="myinput"/>
<div>Loads of other content</div>
<div>Loads of other content</div>
<div>Loads of other content</div>
<ul id="autocomplete"></ul>
</body>
So my question is, is there a way to make the autocomplete append after my given selector rather than appending to the body?
所以我的问题是,有没有办法让自动完成附加在我给定的选择器之后而不是附加到正文?
回答by grongor
You can use option "appendTo"
您可以使用选项“appendTo”
$("#input").autocomplete({
appendTo: $("#input").next()
});
But this can only append to some container as you suspect. If you want to be able to append autocomplete right after your input then you have to tweak the autocomplete source directly (change appendTo() for after())
但这只能附加到您怀疑的某个容器中。如果您希望能够在输入后立即附加自动完成,那么您必须直接调整自动完成源(将 appendTo() 更改为 after())
回答by gregsonian
The original answer helped me to track down an easier solution.
最初的答案帮助我找到了一个更简单的解决方案。
My situation was a little different: I was trying to get a custom autocomplete working in a (Bootstrap) modal. Also, I was using a newer version of jquery-ui (1.11.4). Hopefully my answer will add value to anybody that gets to this posting.
我的情况有点不同:我试图让自定义自动完成在(引导程序)模式下工作。另外,我使用的是较新版本的 jquery-ui (1.11.4)。希望我的回答能为任何看到这篇文章的人增加价值。
According to the documentationfor option appendTo:
根据选项appendTo的文档:
When the value is null, the parents of the input field will be checked for a class of ui-front. If an element with the ui-front class is found, the menu will be appended to that element.
当值为空时,将检查输入字段的父级是否为 ui-front 类。如果找到具有 ui-front 类的元素,则菜单将附加到该元素。
By adding a class ui-frontto a parent element (in my case, the modal), I was able to bring the drop-down-list from behind the scenes and into the modal.
通过向父元素(在我的例子中是模态)添加一个类ui-front,我能够将下拉列表从幕后引入模态。
So you could wrap your input in a container and add to the container the class ui-front.
因此,您可以将输入包装在一个容器中,并将类ui-front添加到该容器中。