Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用循环引导添加行_Javascript_Jquery_Twitter Bootstrap_Pug - Fatal编程技术网

Javascript 使用循环引导添加行

Javascript 使用循环引导添加行,javascript,jquery,twitter-bootstrap,pug,Javascript,Jquery,Twitter Bootstrap,Pug,我想做两列我知道结构是这样的 .row .col-md-6 .col-md-6 .row .col-md-6 .col-md-6 但是如何在javascript中使用循环来编写它呢 - each obj,index in obj if (index > 0) .row .col-md-6 这看起来很直截了当。您必须为循环创建一个嵌套的,该循环使用classrow和classcol-

我想做两列我知道结构是这样的

.row
   .col-md-6
   .col-md-6
.row
   .col-md-6
   .col-md-6
但是如何在javascript中使用循环来编写它呢

    - each obj,index in obj
        if (index > 0)
             .row
                .col-md-6

这看起来很直截了当。您必须为循环创建一个嵌套的,该循环使用class
row
和class
col-md-6
创建
x
div和
y
div

var x = 2,
    y = 2,
    colClass = 'col-md-6',
    rowClass = 'row',
    rows = [],
    i, j, currentRow, currentCol;

// Variable x is the amount of rows to create.
for (i = 0; i < x; i++) {

    // Create the row.
    currentRow = document.createElement('div');
    currentRow.classList.add(rowClass);

    // Variable y is the amount of columns to create for each row.
    for (j = 0; j < y; j++) {

        // Create the column.
        currentCol = document.createElement('div');
        currentCol.classList.add(colClass);

        // Append the column to the row.
        currentRow.appendChild(currentCol);
    }

    // Add the row to an array of rows.
    rows.push(currentRow);
}

// Append the rows to something, or do something else with them.
// Below practice could already be done inside the for loop, instead of rows.push(currentRow)
rows.forEach(function (row) {
    document.body.appendChild(row);
});
var x=2,
y=2,
colClass='col-md-6',
rowClass='行',
行=[],
i、 j,currentRow,currentCol;
//变量x是要创建的行数。
对于(i=0;i
addforloop为“col-md-6”创建2列,或者您需要其他内容?为什么要添加新的“.row”?大于12列单位的行将被简单地删除。您使用的是Jade还是其他什么?这不是正确的Javascript语法