第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何創(chuàng)建在不同頁面上有不同問題的測驗?

如何創(chuàng)建在不同頁面上有不同問題的測驗?

湖上湖 2021-05-02 12:32:19
我想在每個頁面的末尾創(chuàng)建一個小測驗。我有一個用JavaScript編寫的測驗,但我希望不同的問題出現(xiàn)在不同的頁面中。簡而言之,如果我在其他頁面上,我希望const myQuestions更改。我怎樣才能做到這一點?我已經(jīng)嘗試過if語句,但無法實現(xiàn)所需的功能。任何幫助將不勝感激!這是測驗的JS代碼(function() {  const myQuestions = [    {      question: "question 1?",      answers: {        a: "one",        b: "two",        c: "three"      },      correctAnswer: "c"    },    {      question: "question 2?",      answers: {        a: "one",        b: "two",        c: "three"      },      correctAnswer: "c"    },    {      question: "question 3?",      answers: {        a: "one",        b: "two",        c: "three"        d: "four"      },      correctAnswer: "d"    }  ];  function buildQuiz() {    // we'll need a place to store the HTML output    const output = [];    // for each question...    myQuestions.forEach((currentQuestion, questionNumber) => {      // we'll want to store the list of answer choices      const answers = [];      // and for each available answer...      for (letter in currentQuestion.answers) {        // ...add an HTML radio button        answers.push(          `<label>             <input type="radio" name="question${questionNumber}" value="${letter}">              ${letter} :              ${currentQuestion.answers[letter]}           </label>`        );      }      // add this question and its answers to the output      output.push(        `<div class="slide">           <div class="question"> ${currentQuestion.question} </div>           <div class="answers"> ${answers.join("")} </div>         </div>`      );    });    // finally combine our output list into one string of HTML and put it on the page    quizContainer.innerHTML = output.join("");  }  function showResults() {    // gather answer containers from our quiz    const answerContainers = quizContainer.querySelectorAll(".answers");    // keep track of user's answers    let numCorrect = 0;
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經(jīng)驗 獲得超9個贊

里程可能會有所不同,具體取決于您要做什么。僅使用javascript,您就可以windows.location.pathname在每次調(diào)用函數(shù)時傳遞給您的函數(shù),并選擇與所需路徑相關(guān)的問題的合適對象。


if (windows.location.pathname).includes('page1') {

  let currentQuestion = myQuestions[0]

//...rest of the logic


查看完整回答
反對 回復 2021-05-13
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號