2011-10-21 2 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"; 
} 

.

답변

2

사실 내가 알고있는 브라우저에서 작동하지 않습니다. DOM "setAttribute()"함수는 Firefox와 Chrome에서 (그리고 아마도 IE에서도) undefined을 반환합니다.

"체인"코드 스타일은 원하는 경우 JavaScript에서 할 수있는 것이지만 명시 적으로 구현하는 데는 일종의 프레임 워크가 필요합니다. DOM 메소드는 일반적으로 그렇게 작동하지 않습니다.