Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么链接在IE8/9中不起作用_Javascript_Html_Internet Explorer_Dom_Chaining - Fatal编程技术网

Javascript 为什么链接在IE8/9中不起作用

Javascript 为什么链接在IE8/9中不起作用,javascript,html,internet-explorer,dom,chaining,Javascript,Html,Internet Explorer,Dom,Chaining,为什么这样做有效: el = document.getElementById('STR'); if( el ){ el.checked = true; el2 = el.cloneNode(false); el.parentNode.insertBefore(el2, el); el2.setAttribute('id',''); el2.setAttribute('disabled','disabled'); el2.removeAttribut

为什么这样做有效:

el = document.getElementById('STR');
if( el ){
    el.checked = true;
    el2 = el.cloneNode(false);
    el.parentNode.insertBefore(el2, el);
    el2.setAttribute('id','');
    el2.setAttribute('disabled','disabled');
    el2.removeAttribute('name');
    el.removeAttribute("disabled");
    el.style.display="none";
}
但这并不是:

el = document.getElementById('STR');
if( el ){
    el.checked = true;
    el2 = el.cloneNode(false);
    el.parentNode.insertBefore(el2, el);
    el2.setAttribute('id','');
    el2.setAttribute('disabled','disabled').removeAttribute('name');
    el.removeAttribute("disabled");
    el.style.display="none";
}

在Firefox/Chrome中,最后一个代码段工作得非常好。

这在我所知道的任何浏览器中都不起作用。DOM“setAttribute()”函数在Firefox和Chrome(可能还有IE)中返回
未定义的

“链接”代码样式可以在JavaScript中使用,但它需要某种框架来显式实现。DOM方法通常不是这样工作的