【问题标题】:button function change to onload按钮功能更改为 onload
【发布时间】:2017-09-29 14:53:54
【问题描述】:

我想要一个函数写入加载页面加载。此功能仅在页面加载 10 秒后有效。那可能吗?

当我们点击按钮时,我只想显示弹出窗口。一段时间后,我想在加载时更改它。

此代码不起作用。我需要一些未上传的插件和 javascript。请帮我更改onload中的功能

$(function() {
  $("#timeout-example").click(function(e) {
    e.preventDefault();
    $.timeoutDialog({
      timeout: 1,
      countdown: 60,
      logout_redirect_url: 'https://google.com',
      restart_on_yes: false
    });
  });
});
<a href="#" id="timeout-example"> CLICK HERE TO VIEW POPUP </a>

【问题讨论】:

  • 你的问题不清楚

标签: javascript jquery html jquery-ui jquery-plugins


【解决方案1】:

你可以用这个:

var timeLeft = 10;
var showTimerDiv = document.getElementById('showTimer');
var timerId = setInterval(countdown, 1000);

function countdown() {
    if (timeLeft == -1) {
        clearTimeout(timerId);
        doSomething();
    } else {
        showTimerDiv.innerHTML = timeLeft + ' seconds remaining';
        timeLeft--;
    }
}

function doSomething() {
    alert("Hi");
}

在线输出:jsfiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多