IE11错误-调用javascript getAttributeNode方法会制动mergeAttributes [英] IE11 bug - calling javascript getAttributeNode method brakes mergeAttributes

查看:74
本文介绍了IE11错误-调用javascript getAttributeNode方法会制动mergeAttributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE = 7模式下对IE(11.0.27)进行最近更新之后,javasrcipt中确实出现了一些奇怪的行为,在以前的版本中,以下脚本可以正常工作(包括IE8-IE11.0.24).

There is some really strange behavior in javasrcipt after recent update of IE (11.0.27) in IE=7 mode, in previous versions script below works as expected (including IE8-IE11.0.24) .

因此,这是由于调用Element.getAttributeNode(' class ')导致的,在对元素进行此调用之后,如果您尝试将其合并,则该元素将引发错误(未指定错误)带有另一个具有Element.mergeAttributes方法的元素的属性.

So it's caused by calling Element.getAttributeNode('class') , after this call is made on element that element will throw error (Unspecified Error) if you'll try to merge it`s attributes with another element with Element.mergeAttributes method.

演示(仅当 off 且在使用当前IE11版本的IE-7模式下关闭devtools/console时发生): LINK

Demo (happens only when devtools/console is turned off and in IE-7 mode with current IE11 version) : LINK

问题:是否有任何方法可以避免这种情况,并且上述方法有其他替代方法吗?问题是,这两种方法被mootools和jquery选择器大量使用,而我的框架基于mootools.因此,在我使用看起来像$$('input [class = randomclass]')的选择器之后,所有输入都会被破坏,而我将无法克隆它们(mergeAttributes).

Question: Is there any way to avoid this, and is there any alternative methods for those mentioned above? Issue is that those two methods are heavily used by mootools and jquery selectors and my framework is based on mootools. So after I use selector which looks like $$('input[class=randomclass]') all inputs will be corupted and i`ll not be able to clone them (mergeAttributes).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<html>

<head>

    <script type='text/javascript'>
        window.onload = function() {
            org = document.getElementById('o');
            cln = document.getElementById('c');

            btn1 = function() {
                cln.mergeAttributes(org);
                alert(cln.className)
            }

            btn2 = function() {
                org.getAttributeNode('class');
                try {
                    cln.mergeAttributes(org);
                } catch (e) {
                    alert(e.description)
                }
            }

        }
    </script>
</head>

<body>


<div id='placeHolder'>
    Original:
    <input type='text' class='original' id='o'></input>
    <br> Clone:
    <input type='text' class='clone' id='c'></input>
    <br>
</div>

    <input type='button' value='mergeAttributes without "getAttributesNode" ' onclick='btn1()'>
    <br>
    <input type='button' value='mergeAttributes with "getAttributesNode" ' onclick='btn2()'>
    <br>

</body>

</html>

推荐答案

似乎问题出在jQuery库中.该解决方案由dataTabes论坛的cqrranthuohill3提供.他引用了Dottoro.com

It seems the issue is in the jQuery library. This solution was provided by cqrranthuohill3 from the dataTabes forum. He referenced Dottoro.com

在jquery.js中,大约6092行的cloneFixAttributes(src,dest)函数.替换:

In jquery.js in the cloneFixAttributes( src, dest ) function about line 6092. Replace:

// mergeAttributes, in contrast, only merges back on the
// original attributes, not the events
if ( dest.mergeAttributes ) {
    dest.mergeAttributes( src );
}

使用:

   // mergeAttributes, in contrast, only merges back on the
   // original attributes, not the events
    try{
        if ( dest.mergeAttributes ) {
            dest.mergeAttributes( src );
        }
    } catch (exception) {
        for (var i=0; i < src.attributes.length; i++) {
            var attr = src.attributes[i];
            var attrName = attr.name.toLowerCase ();
            if (attrName != "id" && attrName != "name") {
                dest.setAttribute (attr.name, attr.value);
            }
        }
    }

去吧.

这篇关于IE11错误-调用javascript getAttributeNode方法会制动mergeAttributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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