javascript - 如何在 Qualtrics 调查中隐藏下一个按钮直到一天中的某个时间
问题描述
我试图隐藏 Qualtrics 调查中的下一个按钮,直到特定的日期/时间(我的代码中的 var 阈值)。我努力了
Qualtrics.SurveyEngine.addOnload(function()
{
var threshold = '2020-02-07T20:00:00.000Z';
var today = new Date();
if(threshold < today) $('NextButton').hide();
else $('NextButton').show();
});
和
Qualtrics.SurveyEngine.addOnload(function() {
function hideEl(element) {
element.hide();
}
var nb = $('NextButton');
var threshold = '2020-02-07 08:12';
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes();
var dateTime = date+' '+time;
hideEl.defer(nb);
if(var dateTime < threshold ) nb.hide();
else nb.show();
});
和
Qualtrics.SurveyEngine.addOnload(function() {
function hideEl(element) {
element.hide();
}
var threshold = '2020-02-07T20:00:00.000Z';
var today = new Date();
var nb = $('NextButton');
hideEl.defer(nb);
$(this.questionId).on('display', function(event) {
if(today<threshold) nb.hide();
else nb.show();
});
});
但一直无法让它工作。有任何想法吗?
谢谢!!
解决方案
如果您希望加载页面,然后将其留在原处并等待您的按钮显示,那么它将无法工作,因为您的 onload 代码只运行一次。您可以计算页面加载时显示按钮的时间有多远(以毫秒为单位),然后设置超时以在该毫秒数过去后运行显示按钮的代码。
function onLoadCb() {
// When do you want your button to be revealed:
const timeToShow = new Date('<whenver your date is>);
// Convert that to milliseconds:
const msToShow = Number(timeToShow);
// Get the milliseconds right now:
const now = Date.now();
// Do math!
const msToWait = msToShow - now;
// Set a timeout that will wait the number of ms that we calculated:
setTimeout(() => {
// That amount of time has passed, show the button!
$('.NextButton').show();
}, msToWait);
}
推荐阅读
- django - Django如何使ManyToMany字段的每个成员都是唯一的?
- axapta - AOT 查询关系或案例
- amazon-web-services - Alexa 向 AWS Lambda 发送了多个请求
- php - 删除 mysqli_connect() (HY000/2002) 警告并通过 JSON 对象发送错误
- spring-boot - 处理 OneToMany 关系时无法保存父 ID
- jsf - Weblogic 12c R2 (12.2.1.3) 错误 myfaces timeout java.sun.com with web.xml 2.3 tag
- r - 如何从R输出比较Cox回归中不同水平的风险比?
- mysql - 如何使用 Spring MVC 框架从 MySQL 下载 BLOB
- xml - Golang 自定义解组 XML
- sql-server - 实体框架应根据少数列的唯一值集检查重复记录,然后添加新记录