微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 Qualtrics 上设置 null 的innerHTML 属性

如何解决无法在 Qualtrics 上设置 null 的innerHTML 属性

我正在使用 Qualtrics 进行调查,我需要做一些 JS 来制作计时器。不幸的是,我经常遇到元素“s5”的“无法设置 null 的innerHTML 属性”。

我已经阅读了有关此问题的另一个线程(尽管 OP 似乎没有使用 qualtrics),并认为将“Qualtrics.SurveyEngine.addOnload”更改为“Qualtrics.SurveyEngine.addReady”可能会技巧,但它没有,我已经尝试过多次更改 ID 无济于事。有人能帮我找出我的错误在哪里吗?

我之前在同一个问题上被标记过(因为已经有人回答过),但是那个帖子根本没有帮助我。我已经尝试了 ready(),如第一个代码片段中注释掉的部分所示,但这只会给我一个“startThinkingTimer 未定义”错误。当我在第二个代码片段中以第二种方式尝试时,我没有收到任何错误,但我的计时器也根本不可见/不工作。我无法移动脚本或使用 defer b/c Qualtrics 没有在一个文件中包含所有 HTML/CSS/JS,但它们有不同的部分,老实说,我不确定它们如何连接不同的文件。关于使用 .on(),我不确定在这里使用哪个事件,真的很想得到一些帮助。

我已经尝试用这样的东西替换元素“s5”的所有 document.getElementById:

$("s5").innerHTML="10";

但这也不起作用。

(我应该尝试将 html 代码移动到 JS 部分(尤其是 div timeShower 部分)吗?不过我不太确定该怎么做,所以如果有人可以帮助我做到这一点,那就是太棒了。)

window.thinkingTimer_;
window.typingTimer_;

Qualtrics.SurveyEngine.addOnload(function(){
    that = this;
    
    var thinkingTimeLimit = 15;
    var typingTimeLimit = 10;
    
    jQuery(".InputText").hide();
    $('NextButton').hide();
    
    document.getElementById("instructions5").innerHTML = "You have 15 seconds to think about the prompt and come up with your two most favourite fruits,either from the list or from your prevIoUs choices. TextBoxes will appear when the time is up.";

      function startTypingTimer() {
          that.enableNextButton();
          typingTimer_ = setInterval( function(){
              if (typingTimeLimit > 0) {
                  document.getElementById("s5").innerHTML=pad(--typingTimeLimit%60);
                  document.getElementById("minutes5").innerHTML=pad(parseInt(typingTimeLimit/60,10));
              }
              if (typingTimeLimit == 0) {
                  clearInterval(typingTimer_);
                  jQuery("#NextButton").click();
              }
            },1000);
      }
    
    /*
    $(function startThinkingTimer() {
                  that.disableNextButton();
                  thinkingTimer_ = setInterval( function(){
                      if (thinkingTimeLimit >0) {
                          document.getElementById("s5").innerHTML=pad(--thinkingTimeLimit%60);
                          document.getElementById("minutes5").innerHTML=pad(parseInt(thinkingTimeLimit/60,10));
                      }
                      if (thinkingTimeLimit == 0) {
                          clearInterval(thinkingTimer_);
                          document.getElementById("s5").innerHTML="10";
                          document.getElementById("minutes5").innerHTML="00";
                          jQuery(".InputText").show();
                          document.getElementById("instructions5").innerHTML = "You Now have 10 seconds to type in the two fruits. The page will automatically move on to the next page once time is up.";
                          startTypingTimer();
                      }
                    },1000);
              });
    */
    
      function startThinkingTimer() {
            that.disableNextButton();
          thinkingTimer_ = setInterval( function(){
              if (thinkingTimeLimit >0) {
                  document.getElementById("s5").innerHTML=pad(--thinkingTimeLimit%60);
                  document.getElementById("minutes5").innerHTML=pad(parseInt(thinkingTimeLimit/60,10));
              }
              if (thinkingTimeLimit == 0) {
                  clearInterval(thinkingTimer_);
                  document.getElementById("s5").innerHTML="10";
                  document.getElementById("minutes5").innerHTML="00";
                  jQuery(".InputText").show();
                  document.getElementById("instructions5").innerHTML = "You Now have 10 seconds to type in the two fruits. The page will automatically move on to the next page once time is up.";
                  startTypingTimer();
              }
            },1000);
      }
    
    function pad (val) { 
        return val > 9 ? val : "0" + val; 
    }
    
    startThinkingTimer();    

});
<div id="instructions5">&nbsp;</div>

<div id="timeShower1">time: <span id="minutes5">00</span>:<span id="s5">15</span></div>

window.thinkingTimer_;
window.typingTimer_;

Qualtrics.SurveyEngine.addOnload(function(){

    that = this;
    
    var thinkingTimeLimit = 15;
    var typingTimeLimit = 10;
    
    jQuery(".InputText").hide();
    $('NextButton').hide();
    
    document.getElementById("instructions5").innerHTML = "You have 15 seconds to think about the prompt and come up with your two most favourite fruits,1000);
      }
    
    
      $(function () {
          that.disableNextButton();
          thinkingTimer_ = setInterval( function(){
              if (thinkingTimeLimit >0) {
                  document.getElementById("s5").innerHTML=pad(--thinkingTimeLimit%60);
                  document.getElementById("minutes5").innerHTML=pad(parseInt(thinkingTimeLimit/60,1000);
      });
     
    /*
    function startThinkingTimer() {
          that.disableNextButton();
          thinkingTimer_ = setInterval( function(){
              if (thinkingTimeLimit >0) {
                  document.getElementById("s5").innerHTML=pad(--thinkingTimeLimit%60);
                  document.getElementById("minutes5").innerHTML=pad(parseInt(thinkingTimeLimit/60,1000);
      }*/
    
    function pad (val) { 
        return val > 9 ? val : "0" + val; 
    }
    
    //startThinkingTimer();    
    
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。