问答详情
源自:2-3 代码结构调整

Cannot set property 'className' of undefined

Uncaught TypeError: Cannot set property 'className' of undefined
    at refreshDiv (game.js:56)
    at Game.init (game.js:73)
    at Local.start (local.js:11)
    at script.js:2



    var refreshDiv = function(data,divs){  
        for(var i=0; i<data.length; i++){
            for(var j=0; j<data[0].length; j++){ 
                if(data[i][j] == 0){
                    divs[i][j].className = "none";
                } else if(data[i][j] == 1){
                    divs[i][j].className = "none";
                } else if(data[i][j] == 2){
                    divs[i][j].className = "none";
                }
            }
        }
    }

提问者:慕设计6539750 2018-12-30 17:31

个回答

  • qq_Capricorn_9
    2019-05-05 19:46:31

    我也是这个问题一直没解决不知道获取不到这个className问题

  • weibo_命运里拓荒_0
    2019-03-20 21:07:06

    检查.className前面的对象是否成功获取到,如果没获取到肯定报错。你这代码不全,别人也不好看出来