首页 > 解决方案 > Javascript 如果文档包含警报

问题描述

所以我正在做一个测验。我想检查一下 || 虽然文档包含警报。所以如果文档包含警报,那么我想附加我的按钮 Next.So 这是我的想法:

if(document.contains(alert)) {
            const buttonNext = document.createElement("button")
            buttonNext.innerText = "Next"
        } else {
            !document.append(buttonNext)
        }

这是测验部分:

const myBtns = document.querySelectorAll('.Btn')
myQuestionAndAnswers.forEach(item => {
    const myAnswers = item.Answers
    const myQuestion = item.Question
    const mySecondStage = item.SecondStage
    myFunctionForOptions(myAnswers , myQuestion)
})

function myFunctionForOptions(answers, question) {
   const [firstObj, secondObj] = answers // ES6 definening 2 Object in one const variable
   let j
   const remainder = 30 % answers.length + 2
   console.log(remainder)
   for(j = 0;j < (myBtns.length / answers.length + remainder);j++) { //Replacing my Buttons with j
       const typeOfInput = myBtns[j].getAttribute('value') // Getting the value of the input
      myBtns[j].addEventListener('click', (e) => {
          console.log(e.target)
        if(firstObj.option == typeOfInput) { //Checking if the firstObj is the same as the value of the input
        const myTrueAnswer = alert('Hey you got the answer right.Congratulations!')
        } else {
         const myFalseAnswer = alert('You got the answer wrong try next time...')
        }

标签: javascriptdocumentcontains

解决方案


推荐阅读