.on(“click”)在iOS上不起作用

我注意到了

$("body").on("click", "#id", function(event) {... 

在iOS上不起作用

 $("#id").on("click", function(event) {... 

完美的作品。 相同的网站,相同的jQuery(最新),相同的DOM。 我不能使用后者,因为#id是dynamic添加的。

想法?

尝试如下一次:

 $(document).on("click touchstart", "#id", function(event) {... 

如果你想添加点击而不使用触摸事件,你可以做到这一点(虽然它涉及代理嗅探):

 // Check if it is iOS var isiOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false); if(isiOS === true) { // Store -webkit-tap-highlight-color as this gets set to rgba(0, 0, 0, 0) in the next part of the code var tempCSS = $('a').css('-webkit-tap-highlight-color'); $('body').css('cursor', 'pointer') // Make iOS honour the click event on body .css('-webkit-tap-highlight-color', 'rgba(0, 0, 0, 0)'); // Stops content flashing when body is clicked // Re-apply cached CSS $('a').css('-webkit-tap-highlight-color', tempCSS); } 

有关更多信息,请访问http://www.texelate.co.uk/blog/post/124-add-a-click-event-to-html-or-body-on-ios-using-jquery/