为什么/什么时候我必须点击两次才能触发 iOS 上的点击 [英] Why/when do I have to tap twice to trigger click on iOS

查看:48
本文介绍了为什么/什么时候我必须点击两次才能触发 iOS 上的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我觉得我疯了...

Ok I feel like I'm crazy...

我正在查看 iOS 6.0 上的 Mobile Safari.我似乎无法确定何时点击元素会触发点击的任何押韵或原因.在许多情况下,我似乎需要点击一次以触发悬停,然后再次点击以触发点击.

I'm looking at Mobile Safari on iOs 6.0. I can't seem to establish any rhyme or reason as to when tapping on an element will trigger click. In many cases, it seems I need to tap once to trigger a hover and then again to trigger a click.

移动 Safari 规范 说:……单指和两指手势产生的事件流是有条件的,取决于所选元素是可点击的还是可滚动的……可点击的元素是链接、表单元素、图像映射区域或任何其他具有 mousemove、mousedown、mouseup 或 onclick 处理程序的元素...由于这些差异,您可能需要将某些元素更改为可点击元素..."

The Mobile Safari spec says : "... The flow of events generated by one-finger and two-finger gestures are conditional depending on whether or not the selected element is clickable or scrollable... A clickable element is a link, form element, image map area, or any other element with mousemove, mousedown, mouseup, or onclick handlers... Because of these differences, you might need to change some of your elements to clickable elements..."

它继续建议开发人员...添加一个虚拟的 onclick 处理程序,onclick = "void(0)",以便 iOS 上的 Safari 将 span 元素识别为可点击元素."

It goes on to suggest that the developer "...Add a dummy onclick handler, onclick = "void(0)", so that Safari on iOS recognizes the span element as a clickable element."

然而,我的测试表明这些陈述是错误的.

However, my testing has shown these statements to be false.

JsFiddle:http://jsfiddle.net/6Ymcy/1/

html

<div id="plain-div" onclick="void(0)">Plain Div</div>

js

document.getElementById('plain-div').addEventListener('click', function() {
   alert('click'); 
});

尝试在 iPad 上点击元素.什么都没发生

Try tapping the element on an iPad. Nothing Happens

但我离题了.对我来说重要的是找出以下问题:

But I digress. What is important to me is to find out the following question:

究竟是什么条件决定了点击一个元素时会在第一次点击时触发点击"事件?与在第一次点击时触发悬停"事件和第二次点击时点击'事件.

Exactly what are the criteria that determine when clicking on an element will fire a 'click' event on the first tap? As opposed to firing a 'hover' event on the first tap and a 'click' event on the second tap.

在我的测试中,锚元素是唯一可以在第一次点击时触发点击的元素,然后只是偶尔且不一致.

In my testing, anchor elements are the only elements that I can get to fire a click on the first tap, and then, only occasionally and inconsistently.

这就是我开始感到疯狂的地方.我在互联网上广泛搜索,几乎没有发现关于这个问题的信息.只有我吗?!有没有人知道哪里有关于两次点击的标准和/或处理这些限制的方法的讨论?

Here's where I start to feel crazy. I searched the internet far and wide and found next to nothing about this issue. Is it just me?! Does anybody know where there's been any discussion about the criteria for two-taps and or an approach to dealing with these limitations?

我很高兴回答问题/请求.

I'm happy to respond to questions/requests.

谢谢!

推荐答案

我遇到了同样的问题.最简单的解决方案是不要在 iOS(或任何支持触摸的目标平台)上绑定 mouseenter 事件.如果未绑定,则不会触发悬停事件,并且在第一次点击时触发 click.

I had this same issue. The simplest solution is not to bind the mouseenter event on iOS (or any touch enabled target platform). If that is not bound the hover event won't get triggered and click is triggered on the first tap.

这篇关于为什么/什么时候我必须点击两次才能触发 iOS 上的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆