노드 목록을 배열로 변환하려고합니다. 나는 목록 (caption 1,...caption 5
)를 인쇄 할,하지만 인쇄 : 당신은 Array.from()을 사용할 수 있습니다JavaScript : 노드 목록에서 배열로 변환
[object HTMLLIElement],[object HTMLLIElement],[object HTMLLIElement],[object HTMLLIElement],[object HTMLLIElement],[object HTMLLIElement]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Caption</title>
<style>
.captn {
position: absolute;
padding: 10px;
margin: 200px auto;
text-align: center;
font-family:serif, fantasy;
font-size:36px;
color: #009933;
text-decoration: none;
text-transform: uppercase;
list-style-type: none;
}
</style>
</head>
<body>
<div>
<ul id = "caption" class="captn"><li id = "caption0">caption 0</li><li id = "caption1">caption 1</li><li id = "caption2">caption 2</li><li id = "caption3">caption 3</li><li id = "caption4">caption 4</li><li id = "caption5">caption 5</li></ul>
</div>
<script>
var msg;
var cap = [];
var capList;
var f = document.getElementsByClassName("captn");
msg = f.item(0).childNodes;
b = f.item(0).childNodes.length;
var classAr = Array.prototype.slice.call(msg);
document.write(classAr);
</script>
</body>
</html>
오신 것을 환영합니다 스택 오버플로. Minimal, Complete 및 Verifiable 질문을 만드는 방법에 대한 자세한 내용은 [여기를 읽으십시오] (http://stackoverflow.com/help/mcve)를 참조하십시오. – Toby