【问题标题】:Touch events in mobile firefox are not firing移动Firefox中的触摸事件未触发
【发布时间】:2013-10-17 09:59:32
【问题描述】:

我创建了一个非常基本的页面来说明这一点......

<!DOCTYPE html>
<html> <!-- manifest="cache.manifest"-->
<head>

<title>FireFox Touch TEST</title>

<style>

body {width:100%; height:100%; background-color:green;}
div.testdiv {top:0px; left:0px; width:1in; height:1in; background-color:blue;}

</style>

</head> 
<body class="body">

<div id="test" class="testdiv">Touch here</div>

<script type="text/javascript">

  function tStart(event)
  {
    alert("Touched");
  }

  divid = document.getElementById("test");
  divid.addEventListener('touchstart', function(){tStart(event)},false);

</script>   
</body>
</html>

我似乎在做一些根本错误的事情,或者 android 4.2.2 上的移动 Firefox 24 存在问题

任何想法...

【问题讨论】:

    标签: javascript android firefox mobile touch


    【解决方案1】:

    试试这样:

    由于tStart() 中没有这样一个调用event 的变量,浏览器会查看全局对象中是否定义了事件。在 JavaScript 中,全局对象称为window

    function tStart(event)
    {
        alert("Touched");
    }
    
     divid = document.getElementById("test");
     divid.addEventListener('touchstart', function(){tStart(window.event)},false);
    

    【讨论】:

    • 太棒了!我想知道这对 webkit 和 moz 浏览器都有效吗?感谢您及时回复。赞成。
    猜你喜欢
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    相关资源
    最近更新 更多