为什么 jQuery 自动完成功能不弹出?
这是精简的源代码:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将你的调用包装在里面
看起来你的 DOM 还没有准备好。
Wrap your call inside
It looks like your DOM isn't ready yet.
您初始化 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.
尝试将
{source:['one','two','third']}
替换为['one','two','third']
。Try replacing
{source:['one','two','three']}
with['one','two','three']
.如果上述解决方案或此处都无法解决此问题,请确保检查
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 thez-index
. In my case the plugin was working fine, the element was positioned correctly, but the z-index needed to be bumped up.