此事件处理代码是否可以在所有触摸设备上使用? [英] Will this event handling code work on all touch devices?

查看:98
本文介绍了此事件处理代码是否可以在所有触摸设备上使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是否可以在触摸设备上使用. 有人可以为触摸设备提供更好的解决方案吗? 使用JQuery mobile会更好吗?

I'd like to know if this will work on touch devices. Can somebody offer a better solution for touch devices ? Would it be better to use JQuery mobile?

注意::当我问它将起作用"时,我不是在谈论源代码,而是在谈论如何处理触摸设备的方法. 我已经在可正常使用的平板电脑上对其进行了测试,但我不确定其他所有设备. 我想念什么吗?

Note: When I ask "will it work" I'm not talking about the sourcecode but rather about the method how to handle touch devices. I have tested it on my tablet it works, I'm just not sure about every other device. Am I missing something ?

var isTouch = "ontouchstart" in document.documentElement;
var Event;

if(isTouch == true ) {
  Event = "tap";
  console.log("is touch devise");
} else {
 Event = "click";
  console.log("is click devise");
}


$(function () {
    $('#what_ever').on(Event, function() {
        $(this).do_something();
    });
});

我正在寻找什么样的答案?

What kind of answer I'm looking for?

不是,您错了,最好使用此链接 或者 是的,应该可以,您可以使用它处理所有设备.

Nope you are wrong, it's better to use this link or Yep should be ok, you can handle all devices with it.

感谢您的时间

推荐答案

无需注册其他事件处理程序.单击将正常工作.添加 Fastclick ,您最好使用默认的点击处理程序.

There's no need to register a different event handler. Click will work just fine. Add Fastclick and you're good to go with default click handler.

这篇关于此事件处理代码是否可以在所有触摸设备上使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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