问题
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