[英]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.