insertAdjacentElement方法在firefox中报错

来源:互联网 发布:java反序列化 time 编辑:程序博客网 时间:2024/06/05 15:40

原来使用的一个js控件,在firefox3.5.5环境下使用时报错:

container.insertAdjacentElement is not a function

 

原来是firefox没有定义insertAdjacentElement 这个方法,只能自己重定义了,在该控件的脚本中加入以下片段:

      
             HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
                switch(where){
                    case "beforeBegin":
                        this.parentNode.insertBefore(parsedNode,this);
                        break;
                    case "afterBegin":
                        this.insertBefore(parsedNode,this.firstChild);
                        break;
                    case "beforeEnd":
                        this.appendChild(parsedNode);
                        break;
                    case "afterEnd":
                        if(this.nextSibling)
                            this.parentNode.insertBefore(parsedNode,this.nextSibling);
                        else
                            this.parentNode.appendChild(parsedNode);
                        break;
                    }
                }

 

报错信息不再出现。

原创粉丝点击