2 回答

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個贊
您不需要額外的引號:
var i;
for (i = 0; i < document.getElementsByTagName("button").length; i++) {
document.getElementsByTagName("button")[i].style.left = String(Math.floor(Math.random() * 600)) + "px";
}
.game button {
display: inline;
position: absolute;
}
<div class="game" id="divi">
<button class="game"></button>
<button class="game"></button>
<button class="game"></button>
<button class="game"></button>
<button class="game"></button>
<button class="game"></button>
</div>

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個贊
使用此 CSS,所有這些按鈕將相互覆蓋,位于屏幕的左上角。嘗試這個:
.game button {
left: 10px;
display: inline;
position: absolute;
padding-top: 10px;
}
添加回答
舉報(bào)