在iPad上捕获点击DOM / HTML / BODY事件 [英] Catching the Click on DOM/HTML/BODY event on the iPad
问题描述
我正在使用jQuery来检测DOM上的点击 - 或者让每次点击。
I'm using jQuery to detect a click on the DOM - or let's every click.
$(document).click(function(){
alert("Click :-)");
});
除了适用于iPad / iPhone的Safari之外,每个浏览器的效果都很好。我也尝试在html或body元素上应用事件 - 没办法。如何检测iPad / iPhone上的常见点击?
This works pretty good in every browser except Safari for iPad/iPhone. I've also tried to apply the event on the html or body element - no way. How to detect a common click on the iPad/iPhone?
祝你好运,
吉姆
Best regards, Jim
推荐答案
正如我在 http://www.danwellman.co.uk/fixing-jquery-click-events-for-the-ipad/ 您可以测试用户代理并使用touchstart或点击,具体取决于平台
As I found on http://www.danwellman.co.uk/fixing-jquery-click-events-for-the-ipad/ you may test the user agent and use touchstart or click depending on the platform
var ua = navigator.userAgent,
event = (ua.match(/iPad/i)) ? "touchstart" : "click";
$(document).on(event, function (ev) {
...
});
这篇关于在iPad上捕获点击DOM / HTML / BODY事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!