IE 8中的getElementsBySelector失败

时间:2014-12-04 14:40:19

标签: javascript html internet-explorer internet-explorer-8 prototypejs

我正在处理Internet Explorer 8,我有以下代码:

this.scrolling  = false;
    this.wrapper    = $(wrapper);
    //this.scroller = this.wrapper.down('div.elscroller');
    if (this.wrapper.querySelectorAll('div.elscroller') != null ) {
        this.scroller   = this.wrapper.querySelectorAll('div.elscroller');
    }
    this.sections   = this.wrapper.getElementsBySelector('div.seccion');

这在Chrome和Firefox中运行良好,但IE会抛出:对象不支持此行中的此属性或方法:this.sections = this.wrapper.getElementsBySelector('div.seccion');

HTML代码,如下所示:

<div class="elscroller">
  <div class="seccion" id="seccion1"></div>
  <div class="seccion" id="seccion..n"></div>
</div>

正如你所看到的,有一行注释,因为它有同样的问题,所以我采用原始的做事方式,然后放一个if。只有上帝知道如何,但它有效。

我真的厌倦了编码特别是IE8。我希望有一天人们停止使用这个#%!浏览器。

1 个答案:

答案 0 :(得分:0)

如果你正在使用PrototypeJS,那么你可以这样做,这将适用于所有浏览器

this.sections   = this.wrapper.select('div.seccion');

this.sections将是与CSS选择器div.seccion

匹配的DOM元素数组