코드는 다음과 같습니다.
<meta charset = "utf-8"> <title> 제목을 여기에 삽입 </title> </head> <body> <div id = "content"> </div> <cript> var el = document.createElement ( "div"); el.innerhtml = '<html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"/> <titlovalue </title> < ""descrame = " 과학을 배우십시오. " /> <meta name = "keywords"content = "symfony2, redis, php" /> <meta name = "author"content = "csdn.net" /> <meta name = "Copyright"content = "csdn.net" /< /head> < /head> < /head> < /head> < /html> '; var descelements = el.getElementsByTagName ( "Head"); document.getElementById ( "content"). innerHtml = descelements.length; </script> </body> </html>
1. 스크립트를 헤드 요소에 넣으면 스크립트를로드 할 때 DIV 요소가로드되지 않았습니다. 현재 "Document.getElementById (...)는 비어 있거나 객체가 아닙니다".
2. 위의 코드는 일반적으로 크롬으로 분기되며 출력 결과는 5이지만 출력 결과는 0입니다.
3. JS에서 데이터를 정의 할 때 []를 사용할 필요가 없으며, 그렇지 않으면 오류가 발생합니다.