【问题标题】:Document.onclick is not firing on fitbit studioDocument.onclick 没有在 fitbit studio 上触发
【发布时间】:2018-12-26 17:00:04
【问题描述】:


我的 document.onclick 没有在 fitbit studio 上触发。这是我的代码:

import document from "document";
var ctally = 0;
const updateTally = () => {
    var fNum;
    if (ctally <= -1) {
        ctally = 0;
        fNum = "000";
    } else if (ctally < 999) {
        fNum = ("00" + ctally).slice(-3).toString();
    } else {
        fNum = ctally.toString();
    }
    document.getElementById("tally").textContent = fNum;
};
// other code... including a document.onkeypress working fine
document.onclick = () => {
    console.log("Hi!");
    ctally++;
    updateTally();
};

我不知道我做错了什么。两个日志中都不会产生错误。如果它有所作为,为 Fitbit Versa 打造。你好!没有被记录到控制台(这就是我知道它没有触发的原因)。

【问题讨论】:

  • 如果您将onclick 放在其他带有onkeypress 的代码之前,它是否有效?如果是这样,可能是您的其他代码有问题。
  • @Andy no,我的其他代码在翻转时工作正常。

标签: javascript fitbit


【解决方案1】:

设备不支持document.onclick

相反,您可以在 GUI 文件的末尾创建一个新元素 &lt;rect width="100%" height="100%" opacity="0" id="tap-target" pointer-events="all"/&gt;,透明地覆盖整个屏幕,然后将 onclick 处理程序添加到它(document.getElementById('tap-target').onclick = ...。这仅适用于您屏幕上没有其他触摸控件,因为此矩形将捕获所有触摸事件。

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多