Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

jquery - Making a autocomplete textbox/input area

I am trying to make a jQuery autocomplete inputbox, so that people can see suggestions that are pre-set. Not that hard actually, but somehow, I can't seem to solve a problem which won't show up the suggestions.

Here is a fiddle: http://jsfiddle.net/tbBy6/

And this is my HTML file:

<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  <script>
  $(document).ready(function() {
    $("input#search-textbox").autocomplete({
    source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
});
  });
  </script>
</head>

Textbox:

<body>
<input id="search-textbox" class="topic-picker ui-autocomplete-input" type="text" maxlength="100" name="q" accesskey="b"  autocomplete="off" placeholder="enter text" role="textbox" aria-autocomplete="list" aria-haspopup="true">

Why can't I see a suggestion if I type "java" for example?

And my second question: How can I get data from the database to be fetched?

PS: I used the code from here: http://docs.jquery.com/UI/API/1.8/Autocomplete

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're testing in the fiddle you need to change the framework on the left to jQuery, not MooTools, and you will also need to include jQuery UI.

Try this one:

Updated fiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...