简体   繁体   English

如何在输入表单中实现自动填充

[英]How implement auto-fill in input form

I have an ArrayList<String> products where i load them to an input text 我有一个ArrayList<String> products ,将它们加载到输入文本

<select class="form-control">
  <option id="AL9001">AL9001</option>
  <option id="AV8932">AV8932</option>
  <option id="BVE0932">BVE0932</option>
  etc...
</select>

the size of the ArrayList is quite big (2000 elements) so it's not so easy to scroll down 2000 elements to find what you want.. How can I implement an auto-fill fuctionality, where the user starts write sth and the possible elements are shown.. I searched and I found only an html attribute autocomplete where it doesn't work for my case.. ArrayList的大小很大(2000个元素),所以向下滚动2000个元素以查找所需的内容并不是那么容易。我如何实现自动填充功能,在该功能中,用户开始进行写操作,可能的元素是我搜索了一下,但发现只有一个html属性autocomplete ,不适用于我的情况。

One other solution I found is solr where it may fit as my project is build with Tomcat and jsps.. Is there any other way to implement this? 我发现的另一个解决方案是solr ,它可能适合我的项目使用Tomcat和jsps构建的情况。还有其他方法可以实现此功能吗?

Use either the datalist HTML5 element, or the jQuery-ui autocomplete widget (if you need to support old browsers). 使用数据列表 HTML5元素或jQuery-ui 自动完成小部件(如果需要支持旧的浏览器)。 I would also suggest to validate the input before submit, as both datalist and autocomplete work only for <input> and not for <select> , so the user can type anything there. 我还建议在提交之前验证输入,因为数据列表和自动完成功能仅适用于<input>而不适用于<select> ,因此用户可以在此处键入任何内容。 (Not mentioning the obvious server-side validation of the submitted values.) (更不用说明显的服务器端对提交值的验证了。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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