iOS select onchange not firing

≡放荡痞女 提交于 2019-11-27 18:50:50

iOS tends to not fire change events when you change the value of their inputs. I've documented this in more depth at the Device-Bugs tracker.

The workaround is to bind to the blur event instead. In the above example, use onblur and you'll be all set.

<select onblur="window.location=(this.options[this.selectedIndex].value)">

I just ended up setting the form action to a php page that redirects the page. You don't even need a submit button (although you may as well add one for graceful degradation then hide it with js), the iOS list picker widget automatically triggers the form action when it's 'Done' button is pressed.

I originally wanted to avoid form actions and submit buttons because I felt the js onChange approach was cleaner, but I'm fine with using php on iOS since it doesn't require the submit button.

Danny

If you change onchange to onblur it works for iOS but not others. The fix I eventually came to was to use BOTH onblur and onchange. Seems redundant but has the desired effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!