我需要插入一个计时器,并在计时器倒计时后点击到表单的下一页。Here's my form。
我相信我可以使用basic JS或jQuery ( this jQuery plugin看起来很有前途)来实现一些东西。
对于提示页,我需要30秒的倒计时,而对于表单页面,我需要5分钟的倒计时。如何将JS和/或jQuery具体实现到Wordpress和/或重力表单中?
我真的没有太多的代码可以开始,但这是我到目前为止所得到的:
$(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();
});
这段代码不是我自己写的,所以我不确定它是否能工作,或者这是不是正确的轨道。
发布于 2018-04-20 01:36:11
setTimeout应该适用于您的用例。类似这样的内容将在30秒内导航到google.com:
如果超时量是可变的,您可以使用javascript查询数据属性,并用该变量替换30000。
setTimeout(function() {
window.location.href = 'https://google.com';
}, 30000);发布于 2018-04-20 01:42:46
如果您想要的是在计时器启动后以编程方式单击您的$('#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();
});https://stackoverflow.com/questions/49926881
复制相似问题