【问题标题】:Javascript/jQuery Click after TimerJavascript/jQuery 点击计时器
【发布时间】:2018-04-19 17:27:03
【问题描述】:

我需要插入一个计时器,并在计时器倒计时后单击表单的下一页。 Here's my form.

我相信我可以使用基本的 JS 或 jQuery 来实现一些东西(this jQuery plugin 看起来很有希望。

对于提示页面,我需要 30 秒倒计时,而对于表单页面,我需要 5 分钟倒计时。如何在 Wordpress 和/或 Gravity Forms 中具体实现 JS 和/或 jQuery?

我并没有太多的代码可以开始,但这是我目前所掌握的:

$(document).ready(function () {
    seconds = parseInt($("#countdown").attr('data-timelimit'));
    var date = new Date();
    date.setSeconds(date.getSeconds() + seconds);
    $('#countdown').countdown({
        date: date,
        onEnd: goToNextPage,
        render: function(date) {
            return $(this.el).html(""+ (this.leadingZeros(date.min)) + " : " + (this.leadingZeros(date.sec)) + " sec");
        }
    });

    $('#next_button').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        goToNextPage();
    });

我没有自己编写这段代码,所以我不确定它是否有效,或者这是否是正确的轨道。

【问题讨论】:

  • 您好,请在此处发布一个简单明了的代码 sn-p - 不是指向您页面的链接。这不仅可以帮助我们回答问题,还可以帮助未来的搜索者。谢谢!
  • 好的!当然,我会尝试进行相关的编辑。 @AnilRedshift

标签: javascript jquery wordpress forms gravity-forms-plugin


【解决方案1】:

setTimeout 应该适用于您的用例。类似这样的内容将在 30 秒内导航到 google.com:

如果超时量是可变的,您可以使用javascript查询数据属性并将30000替换为该变量。

setTimeout(function() {
  window.location.href = 'https://google.com';
}, 30000);

【讨论】:

  • 能否更改此代码以在我的页面上单击“下一步”?这将如何改变?
  • 应该这样工作吗? setTimeout(jQuery("[value='Next']").click(); }, 500);
【解决方案2】:

如果您想要在计时器到时以编程方式单击您的$('#next_button') 按钮,请尝试此操作。我没用过countdown() 但我想onEnd 接受匿名函数

    seconds = parseInt($("#countdown").attr('data-timelimit'));
    var date = new Date();
    date.setSeconds(date.getSeconds() + seconds);
    $('#countdown').countdown({
        date: date,
        onEnd: function (){
            $('#next_button').click();
        },
        render: function(date) {
            return $(this.el).html(""+ (this.leadingZeros(date.min)) + " : " + (this.leadingZeros(date.sec)) + " sec");
        }
    });

    $('#next_button').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        goToNextPage();
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    相关资源
    最近更新 更多