使用Mobile Safari" form assistant"更改未在选定元素上触发的事件 [英] Change event not firing on select elements with Mobile Safari "form assistant"

查看:79
本文介绍了使用Mobile Safari" form assistant"更改未在选定元素上触发的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这可以按预期工作,但是当用户打开时一个iPhone并使用Mobile Safari的表单助手中内置的下一步按钮,更改事件(使用jQuery)似乎没有触发,第二个选择没有更新。

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 change event (using jQuery) doesn't appear to fire and the 2nd select does not update.

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

仅供参考我也在使用jQuery mobile

FYI I'm also using jQuery mobile

推荐答案

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

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

使用时选择/下拉的onchange()JS事件的行为移动Safari下拉列表项目选择框中的下一步

使用插件(来自上面的链接),我不得不强制选择菜单模糊选择Mobile Safari的表单助手选项后。

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

但是我注意到当蛮力测试这些时菜单额外的模糊事件会在几次来回选择后触发。一个额外的焦点似乎解决了这个问题。

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

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

使用单独的更改函数我正在更新动态第二个选择菜单。

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

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

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

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

这篇关于使用Mobile Safari" form assistant"更改未在选定元素上触发的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆