문서의 HTML 소스를 문자열로 사용하고이 문자열에서 요소가 시작되는 색인 i
이 있습니다.문서의 HTML에서 DOM 요소의 문자열 색인을 가져옵니다.
페이지의 HTML 문자열에서 i
위치에있는 요소에 해당하는 JavaScript DOM 객체를 반환하는 함수 getElementByIndex(i)
이 필요합니다.
> var markup = document.documentElement.innerHTML;
> markup
"<head></head><body><div id="a"></div><div id="b"></div></body>"
> getElementByIndex(19) // 19 is the index of the first div's
// '<' character in the markup string
<div id="a"></div>
> getElementByIndex(19) === document.getElementById("a")
true
> getElementByIndex(19) === document.getElementById("b")
false
'getElementByIndex'에서 기대하는 것이 확실하지 않습니까? 마크 업과 관련이 있습니까? – Rayon
문자열 '
'은 마크 업 문자열에서 위치 19에서 시작합니다. 그것은'getElementByIndex'가 무엇을해야하는지 명확히합니까? –'strng'의'index'? – Rayon