iPhone jQuery click event

隐身守侯 提交于 2019-12-01 22:31:12

问题


I have a simple click event attached to a number of anchors on my web app.

$('a.heading').live("click", function(e) {
   e.preventDefault();
   //do my stuff
});

It's not rocket science. However on my iPhone the click doesn't register. It would appear it uses the touch handler for iPhone (iPad, Android etc are all fine).

I've seen a couple of tutorials but cannot seem to get my head around it. Is there not a one liner that I can use that jQuery is so usually good at?


回答1:


This did the trick:

var userAgent = navigator.userAgent.toLowerCase();
var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1) ? true : false;
clickEvent = isiPhone ? 'tap' : 'click';


来源:https://stackoverflow.com/questions/6828853/iphone-jquery-click-event

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