如果文档包含警报,则使用Javascript

如果文档包含警报,则使用Javascript,javascript,document,contains,Javascript,Document,Contains,所以我在做一个测试。我想检查文档是否包含警报。如果文档包含警报,那么我想在下一步添加我的按钮。这是我的想法: if(document.contains(alert)) { const buttonNext = document.createElement("button") buttonNext.innerText = "Next" } else { !document

所以我在做一个测试。我想检查文档是否包含警报。如果文档包含警报,那么我想在下一步添加我的按钮。这是我的想法:

if(document.contains(alert)) {
            const buttonNext = document.createElement("button")
            buttonNext.innerText = "Next"
        } else {
            !document.append(buttonNext)
        }
这是测验部分:

const myBtns=document.queryselectoral(“.Btn”)
MyQuestions and Answers.forEach(项目=>{
const myAnswers=项。答案
const myQuestion=item.Question
const mySecondStage=item.SecondStage
myFunctionForOptions(我的答案,我的问题)
})
函数myFunctionForOptions(答案、问题){
常量[firstObj,secondObj]=答案//ES6在一个常量变量中定义2个对象
让j
常量余数=30%答案。长度+2
console.log(剩余部分)
对于(j=0;j<(myBtns.length/answers.length+余数);j++){//用j替换我的按钮
const typeOfInput=myBtns[j].getAttribute('value')//获取输入的值
myBtns[j].addEventListener('click',(e)=>{
console.log(例如target)
if(firstObj.option==typeOfInput){//检查firstObj是否与输入值相同

const myTrueAnswer=alert('嘿,你答对了。恭喜你的问题是什么?什么不起作用?为什么
document
包含
alert
-也就是说,什么代码导致
document
获得或失去名为
alert
的属性?-另外,你认为
document.append(buttonNext)是什么
是吗?是的,我忘了删除那个!document.append(buttonNext),但如果你问它意味着document not append buttonNext,那么我的想法是,如果文档包含来自myBtns[j]的警报,那么我想将该按钮附加到我的div中