【问题标题】:How to set time out to this? [duplicate]如何为此设置时间? [复制]
【发布时间】:2019-07-31 02:37:20
【问题描述】:

我希望它在窗口打开 20 秒后自动按下确定按钮。 我不知道该怎么做。 代码是:

window_NameInput.prototype.processHandling = function() {
    if (this.isOpen() && this.active) {

        if (Input.isRepeated('ok')) { 
            this.processOk();
        }
    }
};

我尝试了什么:

window_NameInput.prototype.processHandling = function() {
    if (this.isOpen() && this.active) {

       { setTimeout(function ()   if (Input.isRepeated('ok')) { 
            this.processOk();
        } , 20000); }

    }
};

编辑:

我实际上决定在下面使用此代码。我想在窗口打开 20 秒后调用 ok 处理程序。

Window_NameInput.prototype.processHandling = function() {
    if (this.isOpen() && this.active) {

   setTimeout(function(){

    this.callOkHandler();

},2000);



    }
};

但是我得到了未捕获的类型错误 this.callokhandler is not a function

任何帮助表示感谢提前感谢

【问题讨论】:

  • setTimeout() 回调中的简单错字。
  • 我已经编辑了问题,我决定使用不同的代码,我得到了未捕获的类型错误 this.callokhandler is not a function,你知道如何解决这个问题吗?

标签: javascript time set out


【解决方案1】:

您将if() 条件放在函数{ 之前。

试试:

window_NameInput.prototype.processHandling = function(){
  if (this.isOpen() && this.active) { 
      setTimeout(function() {
        if (Input.isRepeated('ok')) {
          this.processOk();
        }
      }, 20000);
  }
};

希望这会有所帮助,

【讨论】:

  • 我已经编辑了问题,我决定使用不同的代码,但是我得到了未捕获的类型错误 this.callokhandler is not a function,你知道如何解决这个问题吗?
  • 我们必须看到你的callOkHandler函数。 PS,这应该作为一个新问题添加到您之前的问题中。
  • 我是javascript新手,这是完整代码dropbox.com/s/dpbzclydv5sf1fn/rpg_windows.js?dl=0
猜你喜欢
  • 2017-08-01
  • 2016-05-19
  • 2021-06-10
  • 2017-01-10
  • 2010-10-02
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多