【问题标题】:touchend event not firing on iphonetouchend 事件未在 iPhone 上触发
【发布时间】:2017-10-30 02:13:15
【问题描述】:

我正在尝试创建一个基于图像的计数器。 onclick 事件在桌面浏览器和 ipad safari 中运行良好,但在 iphone 中则不行。所以我正在尝试为“touchend”添加事件监听器。它仍然不会在 iphone 中触发。缺什么?谢谢。

<!DOCTYPE html>
<html>
<head>
    <title>Counter</title>
</head>
<body>
    <span class="counter">
    <div>

         <span id="appCounter" style = "font-size:80px">0</span>

         <!--  onclick="changeQty('appCounter', 1); -->
         <img id="plus"
         src='http://www.pixempire.com/images/preview/plus-circular-mini-button-icon.jpg' height='62px' width='62px'></img>
         </div>
         <p>
    </span>

    <script type="text/javascript">

          var elmt = document.getElementById( "plus" );
          elmt.addEventListener('touchend', function(evt) {
            evt.preventDefault();
            changeQty('appCounter', 1);
          }, false);


        function changeQty(elm, val) {
            var obj = document.getElementById(elm);
            obj.innerHTML = Math.min(Math.max(parseInt(obj.innerHTML) + val, 0), 9);
        }
    </script>
</body>
</html>

【问题讨论】:

    标签: javascript iphone onclick


    【解决方案1】:

    使用elmt.ontouchend=function(){};

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2011-12-03
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多