Javascript 自动完成功能适用于 IE 和 Chrome,但不适用于 Firefox
我正在开发一个客户网站,该网站在搜索表单中使用了 Javascript 自动完成功能。该网站是希伯来语的,但请不要让它吓跑您 - 我的问题是代码,而不是英语。 :)
链接:-已被作者删除-
大多数自动完成选项都是希伯来语,但我添加了“测试”,这样也可以很容易用英语进行测试。
基本上,这个自动完成脚本会生成一个文本输入框,当用户输入一个字母(onkeyup
)时,会提供一个常见值列表(例如“test”)。 这在 Chrome 和 IE 中都可以正常工作,但由于某些原因 Firefox 的行为有所不同。
当您在 Firefox 中输入字母时,根据错误控制台:
Error: searchResult1 is not defined
Source File:
Line: 1
第二个输入字段中的 searchResult0
也是如此(源代码中的 ~460 行)。
如果你看看 -removed- 自动完成脚本确实在 Firefox 中工作,所以我真的不知道我可能改变了什么,从而破坏了它的功能。
感谢您对此提供的任何帮助:)
I'm working on a client's site which utilizes a Javascript autocomplete feature in the search form. The website is in Hebrew, but please don't let that scare you away - my issue is in code, not English. :)
Link: -removed by author-
Most of the autocompletion options are in Hebrew but I added "test" so that it will be easy to test in English as well.
Basically this autocomplete script generates a text input box, and when the user types in a letter (onkeyup
), a list of common values are offered (e.g. "test").
This works fine in both Chrome and IE, but for some reason Firefox is behaving differently.
When you enter a letter in Firefox, according to the error console:
Error: searchResult1 is not defined
Source File:
Line: 1
Same goes for searchResult0
in the second input field (line ~460 in the source code).
If you look at -removed- the autocomplete script does work in Firefox, so I don't really know what it is I could have changed that broke its functionality.
Thank you for any help with this :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是
onkeyup="searchResult1.style.visibility='visible';..."
,它应该是document.getElementById('searchResult1').style.visibility
- 您通过 ID 引用一个元素。这是一个旧的 MSIE 功能,带有 ID 的元素会变成“全局变量”,但这实际上不是您应该使用的东西。其他浏览器实现了对此错误功能(“全局范围污染”)的支持,以保持与 MSIE 的兼容性,但它只是一个兼容性层,仅在某些条件下才会起作用。The problem is
onkeyup="searchResult1.style.visibility='visible';..."
, it should bedocument.getElementById('searchResult1').style.visibility
- you are referring to an element by its ID. It's an old MSIE feature that elements with an ID turn into "global variables" but that's really not something you should use. Other browsers implemented support for this misfeature ("global scope pollution") to stay compatible with MSIE but it is merely a compatibility layer and only kicks in under certain conditions.为什么不尝试使用 jquery 自动完成插件而不是自己编写一些东西。 javascript写的不正确。
最好使用 jquery 自动完成插件。我在你的代码中看到你是 jquery1.5.2
自动完成演示:
http://view.jquery.com/trunk/plugins/autocomplete/demo/
下载和文档
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
Why don't you try using jquery autocomplete plugin rather than writing something on your own. The javascript written is not proper.
Its best to use the jquery autocomplete plugin. I see in you code you are jquery1.5.2
Autocomplete Demo:
http://view.jquery.com/trunk/plugins/autocomplete/demo/
Download and documentation
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/