jQuery 'click' event doesn't work on iOS Safari?

匆匆过客 提交于 2019-12-08 09:12:24

问题


This is a strange one. I have a delegated 'click' event that doesn't seem to work on iOS. But if I change the event to 'click touchstart', it works. See below:

$('body').on 'click touchstart', '#cartut-proddetail', ->
  $(@).fadeOut -> $(@).remove()
  $('#cartut-overlay').fadeOut -> $(@).remove()

Basically, #cartut-proddetail is an overlay behind a modal. So when the user taps off the modal, I want to remove all overlays. Without touchstart, though, nothing happens. Why is that? Other click events work just fine on iOS, and I never had to use touchstart before (this is literally the first time). Why doesn't click by itself work?


回答1:


Is very strange, it works me also, tested on iPhone 5S & 4S.

I have an error/success message that is prepended in the html body, and the close button doesn't work if I delegate the click on the body or the document.

I tried click, tap, touch nothing worked until I found your solution. I am still working to find out why it's working.

Thanks for the solution



来源:https://stackoverflow.com/questions/27374764/jquery-click-event-doesnt-work-on-ios-safari

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