簡體   English   中英

html 文件中的 javascript 在我使用 VS Code 的實時服務器中工作正常,但如果我在本地打開 .html 文件,它就不起作用

[英]javascript in a html file works fine in my live server using VS Code but if i open the .html file locally it doesn't work

該代碼基本上用於進行測驗。 我正在使用測驗制作器並復制了他們給我的代碼並對其進行了一些修改。 但問題是,如果我使用實時服務器在 Vs 代碼中啟動它,它就可以正常工作。 但是,如果我從文件夾中打開文件(.html 文件),則沒有任何效果。 我在本地“無法加載資源:net::ERR_FILE_NOT_FOUND”上也有這個錯誤。

    <script>
      (function (i, s, o, g, r, a, m) {
        var ql = document.querySelectorAll('A[quiz],DIV[quiz],A[data-quiz],DIV[data-quiz]');
        if (ql) {
          if (ql.length) {
            for (var k = 0; k < ql.length; k++) {
              ql[k].id = 'quiz-embed-' + k;
              ql[k].href =
                "javascript:var i=document.getElementById('quiz-embed-" +
                k +
                "');try{qz.startQuiz(i)}catch(e){i.start=1;i.style.cursor='wait';i.style.opacity='0.5'};void(0);";
            }
          }
        }
        i['QP'] = r;
        (i[r] =
          i[r] ||
          function () {
            (i[r].q = i[r].q || []).push(arguments);
          }),
          (i[r].l = 1 * new Date());
        (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m);
      })(window, document, 'script', '//cdn.poll-maker.com/quiz-embed-v1.js', 'qp');
    </script>
    <script>
      function closeBanner() {
        const trial = document.querySelector('.trial-box');
        trial.style.display = 'none';
      }
    </script>
<a
      onclick="closeBanner()"
      data-quiz="Q81HSFC7B"
      data-type="5"
      data-fullscreen="true"
      href="https://www.quiz-maker.com/Q81HSFC7B"
      style="
        display: inline-block;
        text-align: left;
        margin: 0 auto;
        width: 100%;
        max-width: 824px;
        box-sizing: border-box;
        text-decoration: none;
        padding: 1em;
        border: 1px solid #ccc;
        color: inherit;
      "
      ><div
        style="
          display: block;
          font-family: sans-serif;
          font-size: 1.5em;
          line-height: 40px;
          color: inherit;
        "
      >
        English Assessment Exam
      </div></a
    >

Failed to load resource: net::ERR_FILE_NOT_FOUND意味着您的 html 中附加的某些資源不存在。

而不是//cdn.poll-maker.com/quiz-embed-v1.js ,只需將其替換為https://cdn.poll-maker.com/quiz-embed-v1.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM