如何使用Javasctipt实现iOS的自动完成?

时间:2021-06-06 14:28:48

I want to auto complete with a list I've defined as i start typing. I figured out how to pull and search the list easy enough but getting the user to select the choices provided (iPhone only) is giving me hell.

我想自动完成我已定义为开始输入的列表。我想出了如何轻松地拉动和搜索列表,但让用户选择提供的选项(仅限iPhone)给了我地狱。

I tried using datalists but that was a dead end and i'm about to just program it from scratch...

我尝试使用datalists,但这是一个死胡同,我即将从头开始编程......

Before I do, I'm wondering if there's something out there that will work for this or if i need to do it all myself. I really like this idea from this post but for a from input.

在我这样做之前,我想知道是否有适合这种情况的东西,或者我是否需要自己完成所有工作。我非常喜欢这篇文章中的这个想法,但是从输入开始。

I could implement the above using a new div to overlay the screen and move the text input to the top when the user types two or more characters and populate a scrollable div with some list items that will redirect back with an onclick.

我可以使用新的div来覆盖屏幕,并在用户键入两个或更多字符时将文本输入移动到顶部,并使用一些列表项填充可滚动的div,然后使用onclick重定向,我可以实现上述操作。

1 个解决方案

#1


1  

Have you tried the jQuery UI Autocomplete? It uses a tag behind so you don't have to worry if you use it in a form.

你试过jQuery UI Autocomplete吗?它使用后面的标签,因此如果您在表单中使用它,则无需担心。

It the input it generates is meesing with the posted data, you can try two things:

它生成的输入是与发布的数据相关联,您可以尝试两件事:

  1. On submit, call a custom AJAX request with your data (collect data in an object from all the input elements, except the generated ones)

    在提交时,使用您的数据调用自定义AJAX请求(从所有输入元素收集对象中的数据,生成的除外)

  2. On submit intercept the event, prevent it, destroy the widget and call another submit on the form (it reverts the html to the original one, without the extra inputs)

    提交拦截事件,阻止它,销毁窗口小部件并在窗体上调用另一个提交(它将html恢复为原始的,没有额外的输入)

#1


1  

Have you tried the jQuery UI Autocomplete? It uses a tag behind so you don't have to worry if you use it in a form.

你试过jQuery UI Autocomplete吗?它使用后面的标签,因此如果您在表单中使用它,则无需担心。

It the input it generates is meesing with the posted data, you can try two things:

它生成的输入是与发布的数据相关联,您可以尝试两件事:

  1. On submit, call a custom AJAX request with your data (collect data in an object from all the input elements, except the generated ones)

    在提交时,使用您的数据调用自定义AJAX请求(从所有输入元素收集对象中的数据,生成的除外)

  2. On submit intercept the event, prevent it, destroy the widget and call another submit on the form (it reverts the html to the original one, without the extra inputs)

    提交拦截事件,阻止它,销毁窗口小部件并在窗体上调用另一个提交(它将html恢复为原始的,没有额外的输入)