Nested for-loop only executing once

前端 未结 2 1592
后悔当初
后悔当初 2021-01-28 08:26

I am using JavaScript and jQuery to create a simple 40x40 grid.

Here\'s my nested for loop to do this:

function display_grid() {
  browser_grid = \'\'
           


        
2条回答
  •  余生分开走
    2021-01-28 09:04

    Thanks for the help guys!

    Changed the variable for my inner loop fixed the problem, but there was a problem with using .append()

    Apparently it doesn't support partial markup, so instead I just appended all of my divs to a string instead.

    for(var i=0;i<40;i++){
                browser_grid+='
    '; for(var x=0;x<40;x++){ browser_grid+="
    "; } browser_grid+='
    '; } $visible_grid.append(browser_grid)

    After which, I appended the string to $visible_grid

    This seemed to do what I wanted it to do. Just wanted to point it out for anyone else using the append method for this purpose.

提交回复
热议问题