【问题标题】:How do I align jQuery autocomplete properly?如何正确对齐 jQuery 自动完成功能?
【发布时间】:2011-09-08 11:55:00
【问题描述】:

这是最不寻常的。我正在我网站上的输入字段上实现 jquery 自动完成,但是当我输入时,建议没有出现在输入字段下。相反,它们显示在 html 文档的最右上角。我需要在这里申请一个特殊的课程来完成这项工作吗?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<link href="js/css/jquery-ui-1.8.13.custom.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>

<script type="text/javascript">
    $(function() {
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
        ];


        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
    </script>
    <style>
        #main{
            width: 200px;
            margin-bottom: 200px auto;
        }
    </style>
</head>

<body>
    <div id="main">
        <div class="ui-widget">
            <input id="tags">
        </div>
    </div>
</body>
</html>

【问题讨论】:

  • 其他事情正在发生。我在 Chrome、Firefox 和 IE7-8 中尝试了你的代码。它在所有这些中都正确对齐。

标签: jquery css jquery-ui autocomplete


【解决方案1】:

我注意到你的和我的不同的是,我们将文本框类设置为 class="ui-autocomplete-input"

【讨论】:

【解决方案2】:

我修好了。 jQuery 版本不够高。它需要 1.5

【讨论】:

    【解决方案3】:
    .ui-autocomplete{
          left:632.5px !important;
          width:305px !important;
      }
    

    在你的 CSS 中使用它来对齐你的自动完成。根据需要改变左边和宽度

    【讨论】:

      猜你喜欢
      • 2012-09-13
      • 2017-07-21
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      相关资源
      最近更新 更多