2017-11-17 16 views
1

私は研究をした後にヒントを得ていないので、私は尋ねるポイントになった。javascriptの出力[オブジェクトのHTMLCollection]

So次のコードでは、divのより正確な配列の内部を単純なブロックとして出力することになっています。 何らかの理由で、すべての "B01"が[object 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, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01, 
 
\t \t \t B01, B01, B01,B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01, B01 , B01]; 
 
\t \t \t 
 

 
\t \t document.write(level); 
 
\t \t
body, html{ 
 
\t margin:0; 
 
\t border:0; 
 
\t width:100%; 
 
\t height:100%; 
 
\t background-color: grey; 
 
} 
 
#game{ 
 
\t width:90%; 
 
\t height: 90%; 
 
\t margin: 0 auto; 
 

 
} 
 

 
.block_matrix{ 
 
\t width:5%; 
 
\t height:5%; 
 
\t background-color:orange; 
 
\t z-index:1; 
 
\t 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>

+1

'document.write()'が何をすることを期待しているのかはっきりしません – Pointy

答えて

0

var B01 = document.getElementsByClassName("block_matrix")[0]; 

または

var B01 = document.getElementsByClassName("block_matrix")[0].outerHTML; 

これはあなたの現在の問題を解決します試してみてください、しかし、あなたがするdocument.writeを使用しているため、あなたは別の問題を満たしています

+0

代わりに何を使うべきですか?私はあなたが言及した限りこれまで働いたと思う。 – Pad

+0

私は本当にあなたの意図が何であるか分かりませんが、今ではすべてのHTMLをレベルに置き換えて、たくさんのblock_matrixを追加したいと思っていますが、まだゲームを続けています。 for(var i = 0; i Pavlo

+0

私は私が必要なものを見つけたと思います。まずはありがとうございます。 – Pad

関連する問題