IE 11:对象不支持属性或方法"getElementsByClassName" [英] IE 11: Object doesn't support property or method 'getElementsByClassName'

查看:672
本文介绍了IE 11:对象不支持属性或方法"getElementsByClassName"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是重复项.先前的问题与IE8有关.这是在IE11中发生的.

This is not a duplicate. Previous questions relate to IE8. This is occurring in IE11.

在Chrome或Firefox中运行此程序没有问题,但是我的代码必须在IE11中正常运行,并且收到以下错误消息:

I have no problems running this in Chrome or Firefox, but my code must function in IE11 and I am receiving the following error:

对象不支持属性或方法"getElementsByClassName"

Object doesn't support property or method 'getElementsByClassName'

function showNext(a) {
    var questions = document.getElementsByClassName("questionholder");
    showRequired.style.display = "none";

    for (var i = 0; i < questions.length; i++) {
        questions[i].style.display = "none";
    }

    var nextQuestion = document.getElementById("question" + a);

    if (nextQuestion !== null) {
        nextQuestion.style.display = "inline-block";
    }
}

应该在这里查看代码:

<form id="TheForm" style="display:block;">
    <div class="questionholder" id="question0" style="display:block">
        <a class="text2button" onclick="showNext(1)">Start</a>
    </div>
    <div class="questionholder" id="question1" style="display:block">
        <a class="text2button" onclick="showNext(2)">Q1</a>
    </div>
    <div class="questionholder" id="question2" style="display:block">
        <a class="text2button" onclick="showNext(3)">Q2</a>
    </div>
</form>

上面的代码将隐藏所有div,然后显示与单击的按钮确定的id"question" + a相匹配的div.

The code above will hide all divs and then show the div that matches the id "question"+a as determined by the button clicked.

如何解决以上错误?

推荐答案

解决方法如下:

<meta http-equiv="X-UA-Compatible" content="IE=11" />

这篇关于IE 11:对象不支持属性或方法"getElementsByClassName"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆