由于在研究之后我没有任何线索,所以我得到了一个问题。
所以下面的代码应该输出数组的内部,因为div作为一个简单的块更精确。 由于某种原因,每个“B01”将作为[对象HTMLCollection]输出,而不是作为css中定义的块。 那么这是怎么发生的呢?我该如何解决呢?
var B01 = document.getElementsByClassName("block_matrix");
var level = [B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01,
B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01];
document.write(level);
body, html{
margin:0;
border:0;
width:100%;
height:100%;
background-color: grey;
}
#game{
width:90%;
height: 90%;
margin: 0 auto;
}
.block_matrix{
width:5%;
height:5%;
background-color:orange;
z-index:1;
position:absolute;
}
<!DOCTYPE HTML>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="script/main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="gfx/style.css" media="screen" />
</head>
<body>
<div id="game">
<script>
</script>
</div>
<div class="block_matrix">
</div>
</body>
</HTML>
答案 0 :(得分:0)
尝试
var B01 = document.getElementsByClassName("block_matrix")[0];
或
var B01 = document.getElementsByClassName("block_matrix")[0].outerHTML;
这将解决您当前的问题,但是您将遇到另一个问题因为您正在使用document.write()