简体   繁体   中英

Autocomplete for dynamically created input using jQuery 3.2.1

I have found autocomplete for dynamically created inputs using jQuery 1.9.1, but I'm using jQuery 3.2.1 (am unable to change the version), kindly give me the solution for jQuery 3.2.1!

The example below is working fine in jQuery 1.9.1:

<script>
 var availableTags = {
     source: ["ActionScript", "AppleScript"],
     minLength: 2
 };
 $("#myProd0").autocomplete({
  source:availableTags
});
  </script>

<html>
<input type="text" name="myProd0" id="productname">
</html>

If I run the code above in jquery 3.2.1, it says autocomplete is not a function .

Check this: http://jsfiddle.net/6mtYe/ (changing to jQuery v3.1.2 won't work)

I think JQuery UI is what you need, check this:

https://jqueryui.com/autocomplete/

If you click on "View source", you'll see an example with jquery version 1.12.4, but if you replace this line:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

for this line:

<script src="https://code.jquery.com/jquery-3.2.1.js"></script>

It still works.

use jquery ui

<script type="text/javascript" src="external/jquery/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="external/jquery-ui/js/jquery-ui-1.12.1.min.js"></script>
<script>
  var availableTags = {
     source: ["ActionScript", "AppleScript"],
     minLength: 2
  };
  $("#myProd0").autocomplete({
   source:availableTags
  });
</script>

check link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM