简体   繁体   English

jQuery自动完成排名

[英]jquery auto-complete position

I am using jquery auto-complete to perform a simple search, I would like to display my result under a text-box. 我正在使用jquery自动完成功能来执行简单的搜索,我想在文本框中显示我的结果。 currently when searching a user, it appends data on top of the text-box so i cannot see what I'am typing. 当前,当搜索用户时,它将数据附加在文本框顶部,因此我看不到我在输入什么。 This is what I have done through online suggestions:. 这是我通过在线建议所做的:

  $("#auto").autocomplete({
            position: { //does not work
                my: "left top ",
                at: "left bottom",
            },
            appendTo: "#results",
            messages: {
                noResults: '',
                results: function () { }
            }, 

I've tried this and it works but it only works after 2nd search: 我已经尝试过了,它可以工作,但是只能在第二次搜索后工作:

   $(function () {
       $("#auto").autocomplete({
       source: data
        });
     $("#auto").autocomplete({
         source: data
             }).autocomplete("widget").addClass("fixed-height");
                });

Try using the position option, specifically the offset property: 尝试使用position选项,特别是offset属性:

HTML: HTML:

<input type="text" id="auto" />
<div id="results"></div>

jQuery: jQuery的:

var data = ['Java', 'JavaScript', 'C', 'C#', 'C++']
$("#auto").autocomplete({
    source: data , 
    position: {
        offset: '0 0' // Shift 0px to the left, 0px down.
    }
});

Working Demo on JSFiddle JSFiddle上的工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM