[英]Autocomplete from scratch using jquery
I know that stackoverflow is not to do my job, for that I ask for generics advices我知道 stackoverflow 不是做我的工作,因为我要求泛型建议
http://www.imobiliare.ro/sugestii/huned
, I need a javascript function, that is continuous read and send information from input text to URL.http://www.imobiliare.ro/sugestii/huned
,我需要一个 javascript 函数,即从输入中连续读取和发送信息文本到 URL。 Eg例如
I have :" http://www.imobiliare.ro/sugestii/huned "+ T , T value from input, Information is pass to URL and generate a JSON, after that http://www.imobiliare.ro/sugestii/huned+T+I , TI values from input.我有:“ http://www.imobiliare.ro/sugestii/huned ”+ T ,来自输入的 T 值,信息被传递到 URL 并生成一个 JSON,然后http://www.imobiliare.ro/sugestii/ huned+T+I ,来自输入的 TI 值。
Hard part for me is how to send continuous that information to url without press a submit button, something like every time I pass a value in input text, is read and send automaticali to URL and make a request对我来说困难的部分是如何在不按下提交按钮的情况下向 url 发送连续的信息,就像每次我在输入文本中传递一个值时一样,被读取并自动发送到 URL 并发出请求
I can't use any existing lib.我不能使用任何现有的库。
Here is some starting points for you, which you should already know if you took a task which says "do not use any libraries".这是您的一些起点,如果您接受了一项“不使用任何库”的任务,您应该已经知道这些起点。 Autocomplete "without using any libraries" is wrong design requirement and a waste of time in almost all cases imaginable.
自动完成“不使用任何库”是错误的设计要求,并且在几乎所有可以想象的情况下都是浪费时间。
That's all.就这样。 You absolutely do not need any "continuous" checking, only key presses.
您绝对不需要任何“连续”检查,只需要按键即可。
For "continuous" checking you should use setTimeout
and setInterval
functions.对于“连续”检查,您应该使用
setTimeout
和setInterval
函数。
EDIT编辑
Here is JsFiddle with the crude solution showing both of my points : you attach an event listener to the text input and then ( with proper debouncing mechanics! ) on key presses you send a request to your backend API.这是 JsFiddle 的粗略解决方案,显示了我的两个观点:您将事件侦听器附加到文本输入,然后(使用适当的去抖动机制! )在按键时向后端 API 发送请求。 Everything else is up to your imagination.
其他一切都取决于您的想象力。 Usually results are returned into a dropdown list, but I certainly would not reimplement that from scratch.
通常结果会返回到下拉列表中,但我当然不会从头开始重新实现它。
这可能会帮助您使用 javascript 从头开始构建自动完成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.