当为touchstart事件调用preventDefault()时,为什么onclick事件被抑制? [英] Why onclick event suppressed, when preventDefault() is called for the touchstart event?

查看:913
本文介绍了当为touchstart事件调用preventDefault()时,为什么onclick事件被抑制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为我的Ipad设备实现一些javascript函数。我想在我的画布div上使用一些滑动动作和点击动作。

I try to implement some javascript functions for my Ipad device. I would like to use some swipe action and click action on my canvas div.

我实现了水平和垂直滑动功能。我必须在touchstart事件上使用preventDefault来防止整个页面滚动时滑动。它工作得很好,但在此之后我注意到它禁用了这个div上的每个点击事件。当preventDefault被删除后,click事件再次起作用。

I implemented the horizontal and the vertical swipe function. I have to use the preventDefault on the touchstart event to prevent the full page scrolling, when swiping. It worked well, but after this I noticed that it disabled every click event on this div. When the preventDefault is removed the click event works again.

有没有解决这个问题的解决方案?

Is there any solution to solve this problem?

dojo.connect(this.node, "ontouchstart", this, "touchstart"); 

...   

touchstart: function(e){
    this.touch = dojo.clone(e.changedTouches[0]);
    e.preventDefault();   
}

this.node = document.getElementById('aa');

this.node = document.getElementById('aa');

<div id="aa" style="width: 600px; height: 400px;">
  <div onclick="alert('asd');" style="width: 100px; height: 100px; background-color: #ff0000; margin: auto;">

  </div>
</div>


推荐答案

您可以尝试阻止touchmove的默认操作事件。

You could try to prevent the default action of the touchmove event.

这篇关于当为touchstart事件调用preventDefault()时,为什么onclick事件被抑制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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