TypeError:无法读取属性< innerHTML为null

时间:2017-02-16 10:44:58

标签: javascript

这里当我检查correctValue等于document.getElementById(' box' + j)时,我遇到了这个错误.nerHTML解释器将第二个看作未定义但是当我更改了document.getElementById (' box' + j).innerHTML with this.innerHTML it work.just我不明白为什么它不能与document.getElementById(' box' + j).innerHTML.for this.innerHTML它引用了我知道的当前元素。我的代码在下面提前谢谢

//if i click on the answer box
    for(j=1;j<5;j++){
      //here i check every box if checked
      document.getElementById('box'+j).onclick=function(){
        //check if im playing
        if(playing==true){
          //if the inner Html of the current box is equal to the correct value
            if(document.getElementById('box'+j).innerHTML==correctValue){
              //we add 1 to the score
            score+=1;
              //we edit the scorevalue span with the new value of score
            editElement('scoreValue',score);
              //we hide the wrong div
            hide('wrong');
              //show the correect div
            show('correct');
              //set time out of 1 second and after that we hide the correct div 
            setTimeout(function(){ hide('correct'); }, 1000);
              //generate new question and answer
            generateQA();
          }else{//if the values are not equal 
            // hide the correct div 
            hide('correct');
            //show the wrong div
            show('wrong');
            //set a time out of 1 second and after that i show the wrong div
            setTimeout(function(){ hide('wrong'); }, 1000);
          }
        }
      };
    }

0 个答案:

没有答案
相关问题