【问题标题】:document addEventListener touchstart does not have any response in Safari console文档 addEventListener touchstart 在 Safari 控制台中没有任何响应
【发布时间】:2020-12-24 16:41:16
【问题描述】:

我正在尝试调试我的代码。下面的代码在 Chrome 中触摸时可以“console.log”消息,但在 Safari 中没有打印出任何消息。有什么建议吗?

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            document.addEventListener('touchstart', function(e) {
            e = e || window.event;
            var target = e.target || e.srcElement,
            text = target.textContent || target.innerText;   
            console.log(target, text);
            }, false);
        </script>
    </body>
</html>

【问题讨论】:

  • 这是 iOS Safari 还是 macOS Safari?
  • 两者。 iOS Safari 或 macOS Safari

标签: javascript html node.js touch-event


【解决方案1】:

目前,dekstop Safari 不支持触​​控 API。

您可以查看兼容性表on MDN 或使用caniuse.com

【讨论】:

  • 对替代方案有什么建议吗?
  • @PakHoCheung 你可以尝试使用一些 polyfill。 Safari 支持 PointerEvents,所以你应该寻找使用它的 polyfill。
猜你喜欢
  • 2019-02-19
  • 2020-06-28
  • 1970-01-01
  • 2022-12-12
  • 2012-03-23
  • 2011-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多