Created
April 17, 2022 11:53
-
-
Save zaynali53/e78457613eb98809970af33021570df4 to your computer and use it in GitHub Desktop.
Autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input id="autocomplete"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const autocomplete = document.querySelector('#autocomplete') | |
| function debounce(callback, delay) { | |
| let timer | |
| return (...args) => { | |
| clearTimeout(timer) | |
| timer = setTimeout(function() { | |
| callback(...args) | |
| }, delay) | |
| } | |
| } | |
| const __e = debounce(function(text) { | |
| console.log(text) | |
| }, 2000) | |
| autocomplete.addEventListener('input', function(event) { | |
| __e(event.target.value) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment