【问题标题】:Check if button has been pressed检查按钮是否被按下
【发布时间】:2020-11-27 19:29:32
【问题描述】:

我想添加一个 if 语句来检查用户是否未为我的程序定义。它应该提醒:“没有更多的配置文件”。 问题是我的“likeId”一开始是未定义的,我第一次运行该函数时会收到警报。我想知道我可以做一个 if 语句来检查某个按钮是否被按下了一次。

这是我的代码:

if (localStorage.getItem('likeId') == "undefined"){
    alert("no more profiles to swipe")
}

我的代码应该是这样的:

if (localStorage.getItem('likeId') == "undefined" && Button has been clicked exactly one time){
        alert("no more profiles to swipe")
    }

【问题讨论】:

  • 按钮有什么作用?你能更清楚地描述这个问题吗?
  • 将事件处理程序绑定到增加点击计数器的按钮。然后比较 if 语句中的计数器值。

标签: javascript if-statement button


【解决方案1】:

只需在调用绑定到按钮的函数时添加一个计数器。然后你检查buttonClickedCounter == 1,你应该很高兴。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    相关资源
    最近更新 更多