JavaScript在循环中创建按钮

JavaScript在循环中创建按钮,javascript,html,Javascript,Html,我想在每个按钮后打断并居中,有什么建议吗?setAttribute不起作用,并且不添加中断 for(var j=0;j HTML <div id='theParent' class='center_the_stuff'> </div> 可能重复的 function addInput(type, value, name, id, onclick, parentId) { //Create an input type dynamically. va

我想在每个按钮后打断并居中,有什么建议吗?setAttribute不起作用,并且不添加中断

for(var j=0;j
HTML

<div id='theParent' class='center_the_stuff'>

</div>
可能重复的
function addInput(type, value, name, id, onclick, parentId) {
    //Create an input type dynamically.   
    var element = document.createElement("input");
    //Assign different attributes to the element. 
    element.type = type;
    element.value = value; // Really? You want the default value to be the type string?
    element.name = name; // And the name too?
    element.id = id;
    element.onclick = onclick;

    var parent = document.getElementById(parentId);
    //Append the element in page (in span).  
    parent.appendChild(element);
}

function addBreak(parentId) {
    var br = document.createElement("br");
    var parent = document.getElementById(parentId);
    parent.appendChild(br);
}

window.onload = function () {
    for (var j = 0; j <= 6; j++) {
        var temp = 'mybutton' + j;
        addInput('button', temp, temp, temp, undefined, 'theParent');
        addBreak('theParent');
    }
}
.center_the_stuff {
    text-align: center;
}