function beggining1(){
for (i=1;i<4;i++){
for (j=1;j<4;j++){
var btn = document.createElement("BUTTON");
btn.className = "button1";
btn.id = i + j;
var t = document.createTextNode(i+"_"+j);
btn.appendChild(t);
document.getElementById("div1").appendChild(btn);
}
}
}
好吧,我基本上是在 div 中做按钮。按钮有样式:
.button1{
background:green;
height:50px;
width:50px;
margin:5px;
}
但它们在一行中位于 div 的顶部,我希望每次第二个循环结束时都做一个断线,这样按钮的位置就会像正方形。我试过
document.write('<br>');
在第二个循环之后但它不起作用有什么建议吗?
最佳答案
试试这个...
document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML +'<br>';
关于javascript - 在制作按钮的javascript循环中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24220642/