gpt4 book ai didi

jquery 自动完成功能不起作用

转载 作者:行者123 更新时间:2023-12-03 22:04:23 26 4
gpt4 key购买 nike

有人可以告诉我为什么我的 jquery 自动完成代码不起作用吗?

这是我的 JavaScript 代码。

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
$("#seed_one").autocomplete({ source: data });
});
</script>

这是我的 html:

<input id="seed_one" type="text" name="seed_one"/><br /> <br />

谢谢

兰斯

最佳答案

Warning: This is an old answer to an old question dating back to 2011. You should be advised to use a more recent release of jQuery and check the API reference for guidance.

您遇到的问题是您正在使用 jQuery Autocomplete plugin但您以调用 jQuery UI autocomplete 的方式来调用它。

如果您使用 jQuery UI 自动完成,代码本身可以正常工作 see in this fiddle 。如果您使用自动完成插件,则必须将调用更改为

$("#seed_one").autocomplete(data);

建议:

  1. 在 jQuery UI 中使用自动完成功能,而不是使用自动完成插件。后者已被弃用。
  2. 修复http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js ,目前无法访问

jQuery UI 的完整代码

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
$("#seed_one").autocomplete({source:data});
});
</script>
</head>

<body>
<input id="seed_one" type="text" name="seed_one"/>
</body>
</html>

自动完成插件的完整代码:

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
$("#seed_one").autocomplete(data);
});
</script>
</head>

<body>
<input id="seed_one" type="text" name="seed_one"/>
</body>
</html>

关于jquery 自动完成功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com