[英]Javascript: Uncaught Type error Autocomplete is not a function
我知道这个问题已经发布了很多,因为我一直在试图找到解决方案的所有答案,但是它不适用于我的代码。
我试图在搜索栏上使用jquery-ui调用自动完成功能,但是每次加载页面时,都会出现类型错误,提示自动完成不是功能。
我已删除了所有加载javascript ui的实例,并将其放在我的javascript文件夹“ jquery-ui-src.php”中的单独文件中,如下所示
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
然后在需要使用jquery-ui的文件中调用它。 我认为捕获错误的文件在我的“ header.php”文件中,该文件充当整个网站的标题
<?php
session_start();
include("assets/js/jquery-ui-src.php");
?>
<header id="header" class="website-header">
//other code included here
//code for the search bar
<form role="search" action="<?php echo SITE_URL; ?>search" method="GET" style="width: 12em; margin: 0.1em 2em;margin-left:7em">
<div class="input-group">
<input type="text" id="tags" class="search-field form-control">
<div class="input-group-btn">
<button type="submit" class="btn btn-default">Search</button>
</div>
</div>
</form>
</div>
//other code included here
<script>
$(document).ready(function(){
$("#account-dropdown").click(function(){
$("#account-box").slideToggle(400);
$(this).css("color", "white");
return false;
});
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>
</header>
每当页面加载时,我都会收到一条错误消息,提示自动完成功能不是功能,我真的不知道为什么要这样做。
任何帮助表示赞赏,谢谢。
编辑
我已经删除了调用jquery脚本的头文件中的第二个实例,但仍然出现错误。
其他信息可能在这里有用,但是我不是制作初始文件的人,因此我得到了一些改善它的任务,其中一个是使用搜索栏,因此了解那里的信息可能会很有用。该项目中有多个文件(实际上很多)。 其中许多也调用不同的脚本,是否应该将所有这些脚本都移到“ jquery-ui-src.php”文件中? 是否有可能解决错误?
因为您要在中间导入另一个jQuery,所以使用jquery-ui-src.php
导入的所有内容均已重置。
请尝试删除此行:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
还有一个无效的结束标记: </div>//other code included here.
去掉它。
以下是工作代码。 这是小提琴 。
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<header id="header" class="website-header">
<form role="search" action="" method="GET" style="width: 12em; margin: 0.1em 2em;margin-left:7em">
<div class="input-group">
<input type="text" id="tags" class="search-field form-control" />
<div class="input-group-btn">
<button type="submit" class="btn btn-default">Search</button>
</div>
</div>
</form>
<script>
$(document).ready(function() {
$("#account-dropdown").click(function() {
$("#account-box").slideToggle(400);
$(this).css("color", "white");
return false;
});
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>
</header>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.