2011-10-21 53 views
-2

工作,爲什麼這項工作:爲什麼不鏈接在IE8/9

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中最後片段完美的作品。

回答

2

這實際上並不適用於我所知道的任何瀏覽器。 DOM「setAttribute()」函數在Firefox和Chrome中(也可能是IE)返回undefined

「鏈接」代碼樣式是您可以在JavaScript中執行的任何操作,但它需要某種類型的框架來明確實現它。 DOM方法通常不會那樣工作。

相關問題