为什么 jQuery 自动完成功能不弹出?

发布于 2024-10-16 01:38:36 字数 1639 浏览 3 评论 0原文

这是精简的源代码:

<html>
    <head>
        <script type="text/javascript" src="/admin/jsi18n/"></script>
        <link href="/media/css/ui-lightness/jquery-ui-1.8.9.custom.css" type="text/css" media="screen" rel="stylesheet" />
        <script type="text/javascript" src="/media/admin/js/core.js"></script>
        <script type="text/javascript" src="/media/admin/js/admin/RelatedObjectLookups.js"></script>
        <script type="text/javascript" src="/media/admin/js/jquery.min.js"></script>
        <script type="text/javascript" src="/media/admin/js/jquery.init.js"></script>
        <script type="text/javascript" src="/media/admin/js/actions.min.js"></script>
        <script type="text/javascript" src="/media/js/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="/media/js/jquery.autocomplete.pack.js"></script>
    </head>
    <body> 
        <div>
            <label for="id_postal_code" class="required">Postal code:</label>
            <input type="text" name="postal_code" id="id_postal_code" />
            <script>$('#id_postal_code').autocomplete({source:['one','two','three']});</script>
        </div>
    </body>
</html>

我试图在文本框中输入“o”,但没有出现任何内容。

它将这个 autocomplete='off' 属性和 class='ac_input' 添加到输入中,所以......它似乎初始化正确,我只是不知道为什么什么都没有出现。

如果我查看 firefox 中的源代码,每次按下按键时 ac_input 都会闪烁,因此每次我键入内容时它似乎都会设置类,但自动完成功能永远不会切换到“on” (我猜在某个时候应该如此?)。

Here's the condensed source code:

<html>
    <head>
        <script type="text/javascript" src="/admin/jsi18n/"></script>
        <link href="/media/css/ui-lightness/jquery-ui-1.8.9.custom.css" type="text/css" media="screen" rel="stylesheet" />
        <script type="text/javascript" src="/media/admin/js/core.js"></script>
        <script type="text/javascript" src="/media/admin/js/admin/RelatedObjectLookups.js"></script>
        <script type="text/javascript" src="/media/admin/js/jquery.min.js"></script>
        <script type="text/javascript" src="/media/admin/js/jquery.init.js"></script>
        <script type="text/javascript" src="/media/admin/js/actions.min.js"></script>
        <script type="text/javascript" src="/media/js/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="/media/js/jquery.autocomplete.pack.js"></script>
    </head>
    <body> 
        <div>
            <label for="id_postal_code" class="required">Postal code:</label>
            <input type="text" name="postal_code" id="id_postal_code" />
            <script>$('#id_postal_code').autocomplete({source:['one','two','three']});</script>
        </div>
    </body>
</html>

I'm trying to type 'o' in the textbox, but nothing appears.

It's adding this autocomplete='off' attribute and class='ac_input' to the input, so... it seems to be initializing correctly, I just don't know why anything isn't appearing.

If I look at the source code in firefox, that ac_input flashes every time I hit a key too, so it seems to be setting the class every time I type something, but autocomplete never switches to "on" (which I'm guessing it ought to at some point?).

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

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

发布评论

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

评论(4

把回忆走一遍 2024-10-23 01:38:36

将你的调用包装在里面

$(function() { 
  // your code here... 
});

看起来你的 DOM 还没有准备好。

Wrap your call inside

$(function() { 
  // your code here... 
});

It looks like your DOM isn't ready yet.

浅浅淡淡 2024-10-23 01:38:36

您初始化 jQuery 两次 - admin/jquery.min.js 和 js/jquery-1.4.4.js

尝试修复该问题。

You initialize jQuery twice -- admin/jquery.min.js and js/jquery-1.4.4.js

Try fixing that.

旧竹 2024-10-23 01:38:36

尝试将 {source:['one','two','third']} 替换为 ['one','two','third']

Try replacing {source:['one','two','three']} with ['one','two','three'].

许久 2024-10-23 01:38:36

如果上述解决方案或此处都无法解决此问题,请确保检查 ul.ui-autocomplete 元素的页面标记并检查 z-index。就我而言,插件工作正常,元素定位正确,但 z 索引需要提高。

If none of the solutions above or here solve this issue, be sure to check the page markup for a ul.ui-autocomplete element and check the z-index. In my case the plugin was working fine, the element was positioned correctly, but the z-index needed to be bumped up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文