简体   繁体   English

如何在60秒后将自动点击功能添加到按钮并使用javascript执行该操作?

[英]How can I add automatic click functionality after 60second to button and perform that operation using javascript?

I tried solutions for similar asked questions before but they are not working for my purpose This is my button 我之前尝试过类似问题的解决方案,但这些解决方案无法满足我的目的。这是我的按钮

 <a class="goto-next-slide overlay-button overlay-right" id="nxt">Next</a>    

this is my javascrit function which is performing click operation 这是我执行点击操作的javascrit函数

function gotoNextSlide() {
goToSlide(getCurrentSlide().index() + 1);
 }

Now the event is happening only when I clicked the button but what should I do to perform operation when next button get clicked automatically after 60 seconds. 现在,仅当我单击按钮时才发生该事件,但是当60秒后自动单击下一个按钮时,我应该怎么做才能执行操作。 this is my jquery where I am calling the gotoNextSlide() function. 这是我的jQuery,我在其中调用gotoNextSlide()函数。

function init() {
$("#nxt").click(gotoNextSlide);
}
$(document).ready(init);

how can I do it? 我该怎么做?

I tried by this method 我尝试过这种方法

<script>
    var tmp;
    function f1() {
        tmp = setTimeout("(gotoNextSlide)", 2000);
    }
    function callNext() {
        document.getElementById("nxt").click();
    }
</script>

Use setTimeout to queue goToNextSlide after 60 seconds. 60秒钟后,使用setTimeout将goToNextSlide排队。 Whenever someone clicks "next" button or 60 seconds passed, clear the timeout, change the slide, and queue it again after 60 seconds. 每当有人单击“下一步”按钮或经过60秒时,请清除超时,更改幻灯片,然后在60秒后再次排队。

var timer;

function gotoNextSlide() {
   timer && clearTimeout(timer);
   goToSlide(getCurrentSlide().index() + 1);
   timer = setTimeout(gotoNextSlide, 1000 * 60);
}

function init() {
  $("#nxt").click(gotoNextSlide);
  timer = setTimeout(gotoNextSlide, 1000 * 60);
}
$(document).ready(init);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM