'getElementsByClassName'메소드가없는 브라우저의 특정 클래스 이름의 모든 요소를 가져 오는 메소드를 작성하려고합니다. 이것은 서버 측에서 생성되는 요소에 대해 완벽하게 작동하지만 'window.document.all'이 이러한 동적 요소를 얻지 못하는 이유 때문에 페이지에 동적으로 요소를 추가 할 수 있습니다. 어떤 아이디어? 아래 방법.document.getElementsByTagName을 사용하면 동적으로 추가 된 요소를 찾을 수 없습니다. (IE6)
function getClassName(class) {
var i, neededStuff = [], elements = document.getElementsByTagName('*');
for (i = 0; i < elements.length; i++) {
if (elements[i].className == class) {
neededStuff[neededStuff.length] = elements[i];
}
}
return neededStuff;
}
어떤 좋은 자습서? –
oops, getElementsByTagName을 사용하고 있었지만 게시하기 전에 'window.document.all'로 바꾸어 무언가를 테스트했습니다. – ploosh