javascript - 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...')
}
解决方案
推荐阅读
- python-3.x - 如何使用 rgb 值在 pandas.scatter_matrix 中添加颜色?
- node.js - 我安装了 react js,但是当输入 npm start 时,他给出了一个错误
- r - 在 R 中使用 readMM 函数时出错:文件不是 MatrixMarket 文件;以及如何将其存储为 igraph 对象
- python - 我正在为一个挑战构建一个脚本,该脚本使用目录的单词列表请求页面的状态代码。如何通过 TOR 过滤它?
- python - cffi python包不匹配的错误版本
- clickhouse - Clickhouse 内存问题
- javascript - TensorFlowJs - 无法加载图像并将其从资产转换为张量
- python - 在另一台笔记本电脑上克隆环境时出现 Conda HTTP 错误
- python - 如何在标点符号前自动删除空格
- python - 有什么方法可以获取网络应用用户 IP 地址