簡體   English   中英

Jquery自動完成無法在Jquery .load()文件中工作

[英]Jquery Auto Complete Not Working in Jquery .load() File

我有一個由$(“#area”)。load('edit.php')調用的表單。 在該edit.php文件中,我想要一個可以應用自動補全的字段。 我試圖將javascript放入edit.php文件中,但無法正常工作。 然后我嘗試將javascript放在主文件中; 它也不起作用。 為什么? 請幫我。

這是我從http://jqueryui.com/autocomplete/獲得的javascript

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(function() {
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>

和html:

<label for="tags">Tags: </label>
<input id="tags">

附:我也曾嘗試在單個php文件中(沒有load。()),但一切正常。 但是在這種情況下不行。

在CDN的前面使用HTTP或https

  <link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
      <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

嘗試將函數放在window.onload()方法中。

   $(window).load(function() {
          $(function() {
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
});
});
    }); 

HTML應該是

<body> 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div> 
</body>

請在瀏覽器(chrome)中使用inspect元素 ,查看上述CDN是否已正確加載

在此處輸入圖片說明

//code.jquery.com/jquery-1.9.1.js
//code.jquery.com/ui/1.10.4/jquery-ui.js

我認為您的jQuery文件未加載請復制URL並獲取源代碼並將文件保存在.js中

您需要的是腳本的完整http路徑:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

有關工作示例,請參見此小提琴

您可以看到針對加載的獲取請求,並且可以看到正在加載的正確數據嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM