jQuery 使用 Mobile Safari“表单助手”更改事件不会在选择元素上触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7680992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:09:46  来源:igfitidea点击:

Change event not firing on select elements with Mobile Safari "form assistant"

jqueryiphoneiosjquery-mobilemobile-safari

提问by wdm

I have dynamic select drop-down menus. For example, if you select a specific month, the 2nd select element will populate with number of days in that month.

我有动态选择下拉菜单。例如,如果您选择特定月份,则第二个选择元素将填充该月的天数。

This works as intended, however when the user is on an iPhone and uses the "Next" button built into Mobile Safari's "form assistant", the changeevent (using jQuery) doesn't appear to fire and the 2nd select does not update.

这按预期工作,但是当用户使用 iPhone 并使用 Mobile Safari 的“表单助手”中内置的“下一步”按钮时,change事件(使用 jQuery)似乎不会触发,并且第二个选择不会更新。

$('.month').change(function() {
    // update "days" select element
});

FYI I'm also using jQuery mobile

仅供参考,我也在使用 jQuery mobile

采纳答案by wdm

The best work-around I could find was based on this post...

我能找到的最好的解决方法是基于这篇文章......

Strange behavior of select/dropdown's onchange() JS event when using 'Next' on Mobile Safari Dropdown list item select box

在 Mobile Safari 下拉列表项选择框上使用“下一步”时,选择/下拉的 onchange() JS 事件的奇怪行为

Using the plugin (from the link above), I had to force the select menu to bluras soon as an option was chosen with Mobile Safari's "form assistant".

使用插件(来自上面的链接),blur一旦使用 Mobile Safari 的“表单助手”选择了一个选项,我就必须强制选择菜单。

I noticed however when brute force testing these menus an extra blurevent would fire after a few back-and-forth selections. An extra focusseemed to fix that.

然而,我注意到当蛮力测试这些菜单时,blur会在几次来回选择后触发一个额外的事件。一个额外的focus似乎解决了这个问题。

$('select').quickChange(function () {
    $(this).blur();
    $('select').focus(); // somehow prevents an extra blur from firing on focus
});

With a separate changefunction I am updating the second select menu dynamically.

使用单独的change功能,我正在动态更新第二个选择菜单。

$("#select-choice-month").change(function () {
    // update second select dynamically
});

*Only tested on Mobile Safari / iOS 5.0.1 thus far.

*目前仅在 Mobile Safari / iOS 5.0.1 上进行过测试。

回答by Andy

You could also bind some additional events like blur( don't know if blur does fire on iphone though)

你也可以绑定一些额外的事件,比如blur(虽然不知道模糊是否会在 iphone 上触发)

$('.month').bind('change blur',function(){

});

or have you tried:

或者你试过:

$('.month').live('change',function(){
});