自动完成组合框在失去焦点时重置 - 仅限 IE
我在页面上的多个组合框上使用 jquery.ui.autocomplete 。仅在 IE 中,组合框会在失去焦点时重置 (onBlur)。再多的 JS 调试也无法揭示原因。有什么建议吗?
I am using jquery.ui.autocomplete on multiple comboboxes on a page. In IE only, the combobox resets on loss of focus (onBlur). No amount of JS debugging can reveal the cause. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这就是我的想法。我使用了你的代码并复制了你的错误。
之所以说IE不一样...firefox,就是这个套路:
在firefox中,ui.item不为null,在IE中却是。所以在 IE 中它必须获取 '
' 的实际值value 属性,并与文本框中的内容进行比较。问题是:
value="foo" 必须与 >foo< 中的内容完全匹配。
当你模糊时会导致它清除字段
不会
在firefox和chrome中,他们通过ui所以他们不会得到这个检查,它只是继续,一切都很酷。检查以确保您的值与选项文本完全匹配。
Ok, here's what I came up with. I used your code and replicated your bug.
The reason that IE is different then say... firefox, is this routine:
In firefox, ui.item is not null, in IE it is. So in IE it has to get the actual values of '<option value="foo">foo</option>' the value attribute, and compare with whats in the text box.
Here's the problem:
value="foo" must match exactly what is in >foo<
Will cause it to clear the field when you blur
Will not
In firefox and chrome, they pass ui so they don't get this check, it just continues on and everything is cool. Check to make sure your values match exactly what the option text is.
superfro 的分析是正确的,但是如果您修改这一行代码,则可以使用
option
元素,其中值与文本不同:to:
这样,您就可以与
内部的 TEXT 进行匹配
而不是 VALUE。superfro's analysis is correct, but you can use
option
elements where the value differs from the text if you modify this single line of code:to:
This way, you're matching against TEXT inside of
<option value="VALUE">TEXT</option>
instead of VALUE.