我在JavaScript的简单搜索表中遇到麻烦
我知道我坚持的事情很简单。
我的示例在这里:
一开始什么都没有。当您在搜索表中键入第二或第三个字母时,它们开始出现。那不是很棒吗?
感谢您的帮助。
I know what I'm stuck with is simple.
My example is here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_filter_list
I want to do the opposite. Nothing appears at first. They start appearing as you type the 2nd or 3rd letter in the search form. Wouldn't that be great?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑一些方法,因为现在我可以向您展示一个仅稍微编辑您当前代码的解决方案。
为了更好地告诉您我更改了哪些行,我将您的代码移至JSFiddle。
”您描述的功能,一旦输入2个字符或更多字符,它就会开始显示列表。
第一个更改是在HTML部分的第5行中;
我们已经做到了,因此您的列表一开始就不可见。
然后在JavaScript部分,第8至12行,我们添加了以下内容;
因此,如果您的过滤器具有超过1个字符,请显示列表,否则隐藏列表。
我希望这有所帮助!如果您愿意,我可以向您展示一些如何更好地构建这样的搜索列表的方法。
There's a couple approaches you can consider, for now I can show you a solution that only edits your current code slightly.
To better tell you what lines I've changed, I've moved your code over to a JSfiddle.
https://jsfiddle.net/ubLve2hx/1/
I've edited your code to fit the functionality you describe, it starts showing the list once you've typed 2 characters or more.
The first change is at line 5 of the HTML section;
We've made it so your list isn't visible to begin with.
Then at the javascript section, line 8 to 12 we've added the following;
So if your filter has more than 1 character, show the list, else hide the list.
I hope this has helped! If you want I can show you some approaches on how to better structure search lists like this.