ie8中此操作错误的源HTML无效

时间:2012-12-11 12:55:38

标签: javascript internet-explorer extjs

我得到了

SCRIPT601:此操作的源HTML无效。

ext-all-debug.js,第6769行第21期

IE 8中的

这就是这条线。

el.insertAdjacentHTML(hashVal[0], html);

调试时,html中的值为"<a title=\"\">1</a>"

我坚持这个问题好几天了。这与评级功能有关。我认为由于这个错误,评级星没有显示在ie 8.其他浏览器都可以。 我在下面给出了相应的代码部分。我正在使用extjs。

var starLink = star.createChild({
            tag: 'a',
            html: this.values[i],
            title: this.showTitles ? this.titles[i] : ''
        });

在创建此元素时,调用将转到以下部分,并在上面指定的行上发生错误。

 insertHtml : function(where, el, html){
            var hash = {},
                hashVal,
                range,
                rangeEl,
                setStart,
                frag,
                rs;

            where = where.toLowerCase();

            hash[beforebegin] = ['beforeBegin', 'previousSibling'];
            hash[afterend] = ['afterEnd', 'nextSibling'];


            if (el.insertAdjacentHTML) {
                if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
                    return rs;
                }


                hash[afterbegin] = ['afterBegin', 'firstChild'];
                hash[beforeend] = ['beforeEnd', 'lastChild'];
                if ((hashVal = hash[where])) {
                    el.insertAdjacentHTML(hashVal[0], html);
                    return el[hashVal[1]];
                }

            } else {

2 个答案:

答案 0 :(得分:1)

使用.innerHTML,.insertAdjacentHTML等类似的IE非常挑剔。

传递的HTML必须完美结构化 - 它不允许任何类型的任何错误。如果有,它根本不会这样做。其他浏览器将执行与文档其余部分相同的“最佳猜测”。

尝试将非常简单的内容添加为HTML值:

<p>Hello World!</p>

你应该发现它有效。在这种情况下,您需要找到您提供的HTML的错误。如果它不起作用,那么你还有另一个问题。

答案 1 :(得分:1)

虽然我们不知道您正在创建哪些元素以及在哪里,但我认为您正在尝试向tr添加新的table元素。然而,这在IE&lt;中是不可能的。 10.较旧的IE与其他浏览器具有完全不同的表模型,并且无法使用insertAdjacentHTML()访问表来创建行(可以创建td)。对于innerHTMLtable的直接后代,tr也是只读的。

在IE中向表中添加新行的最佳方法是使用insertRow(index)方法。 index是您要添加行的位置。默认情况下,index为-1,在表的末尾添加一个新行。

MSDN上的这篇文章Building Tables Dynamically可能会有所帮助。

BTW if ((hashVal = hash[where]))不再是新浏览器中的有效语法。