简单的jquery自动完成输入框无法正常工作

时间:2014-06-23 13:15:09

标签: jquery css jquery-ui autocomplete

我正在尝试在输入文本框上实现自动完成功能。我复制了所有代码,但它似乎不起作用。这是来自jquery网站的相同代码(自动完成示例)任何帮助?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <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>
</head>
<body>

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


</body>
</html>

//控制台错误

Failed to load resource: net::ERR_FILE_NOT_FOUND file://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///C:/resources/demos/style.css
Failed to load resource: net::ERR_FILE_NOT_FOUND file://code.jquery.com/ui/1.10.4/jquery-ui.js
Failed to load resource: net::ERR_FILE_NOT_FOUND file://code.jquery.com/jquery-1.10.2.js
Uncaught ReferenceError: $ is not defined /C:/Users/Saad/Desktop/tHome.html:11

任何帮助?

2 个答案:

答案 0 :(得分:2)

更改此

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

这个

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.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.10.4/jquery-ui.js"></script>

问题是你在本地测试它需要在开头添加http才能使用

答案 1 :(得分:0)

<script src=" HTTP: //code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

或者你删除http:因为StackOverflow?