自动完成组合框在失去焦点时重置 - 仅限 IE

发布于 2024-10-03 20:50:14 字数 100 浏览 13 评论 0原文

我在页面上的多个组合框上使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苹果你个爱泡泡 2024-10-10 20:50:14

好的,这就是我的想法。我使用了你的代码并复制了你的错误。

之所以说IE不一样...firefox,就是这个套路:

                                    change: function (event, ui) {
                                        if (!ui.item) {

在firefox中,ui.item不为null,在IE中却是。所以在 IE 中它必须获取 '

' 的实际值value 属性,并与文本框中的内容进行比较。

问题是:

value="foo" 必须与 >foo< 中的内容完全匹配。

<option value="5">Five</option> 

当你模糊时会导致它清除字段

<option value="Five">Five</option>

不会

在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:

                                    change: function (event, ui) {
                                        if (!ui.item) {

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<

<option value="5">Five</option> 

Will cause it to clear the field when you blur

<option value="Five">Five</option>

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.

吃兔兔 2024-10-10 20:50:14

superfro 的分析是正确的,但是如果您修改这一行代码,则可以使用 option 元素,其中值与文本不同:

if (this.value.match(matcher)) {

to:

if ($(this).text().match(matcher)) {

这样,您就可以与 内部的 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:

if (this.value.match(matcher)) {

to:

if ($(this).text().match(matcher)) {

This way, you're matching against TEXT inside of <option value="VALUE">TEXT</option> instead of VALUE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文