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

发布于 2024-12-08 20:08:20 字数 299 浏览 3 评论 0原文

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

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

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

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

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

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

FYI I'm also using jQuery mobile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

演多会厌 2024-12-15 20:08:20

您还可以绑定一些其他事件,例如 blur (不过不知道 Blur 是否会在 iPhone 上触发)

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

});

或者您尝试过:

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

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

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

});

or have you tried:

$('.month').live('change',function(){
});
盛夏已如深秋| 2024-12-15 20:08:20

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

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

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

然而,我注意到,当强力测试这些菜单时,在几次来回选择后会触发额外的模糊事件。额外的焦点似乎可以解决这个问题。

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

通过单独的 change 函数,我动态更新第二个选择菜单。

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

*迄今为止仅在 Mobile Safari / iOS 5.0.1 上进行了测试。

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

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
});

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

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