失去焦点时自动完成检查
如何确保输入字段中的值始终仅具有来自源的值?
例如,如果在源中我有
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
数据库驱动的实际脚本:
source: "get_json.aspx";
并且在输入字段中我仅键入“冷”,我该如何阻止这种情况发生?
当输入字段失去焦点时,如何确保该值存在于源中?
How do I ensure the value in the input field always has a value from the source only?
For example, if in the source I have
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
which is database driven as the actual script is:
source: "get_json.aspx";
and in the input field I type just "cold", how do I stop this from happening?
How do I ensure that the value exists in the source when focus is lost from the input field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该绑定到正确的事件。我认为你应该绑定到 关闭事件。然后检查 输入值 包含元素 数组中。否则,您应该使用 val 再次将输入设置为空。我自己在本地测试了一下,确实有效。
PS:我做了一些更多的测试,我认为你应该将它绑定到另一个事件。因为当您点击导航栏时它不起作用。我认为你应该绑定到 blur 事件。
改进后的代码=>
json转数组=>
json.txt:
You should bind to proper event. I think you should bind to close event. then check value of input contains element in array. Else you should make input empty again using val. I tested it myself locally and it does the trick.
P.S: I did some more testing and I think you should bind it to another event instead. Because when you tab to navigation bar it does not work. I think you should bind to blur event instead.
The improved code =>
json to array =>
json.txt: