简体   繁体   English

未捕获(承诺)TypeError:无法将属性'innerHTML'设置为null

[英]Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null

I understand there are questions similar to this issue. 我了解有些问题与此问题类似。 And I have taken the time to look through them. 我花了一些时间仔细研究它们。 But the implementation here is a little different than in some of the cases I looked at. 但是,这里的实现与我研究的某些情况有些不同。 The good news here is my fourth column, the running totals column, is correctly displaying the data I want. 好消息是我的第四列,即运行总计列,正在正确显示我想要的数据。 Everything is working (correctly calculated and displaying) so why is my app held up on this? 一切正常(正确计算并显示),那么为什么我的应用程序无法正常运行? I'd appreciate it. 我会很感激的。 Thanks. 谢谢。

在此处输入图片说明

calculateRunningTotals(){
        var attendantTotalCell = 0;
        var total = 0;
        var totalCell="";
        var totalsCells = document.querySelectorAll("td:nth-child(3)");

        totalsCells.forEach(function(cell, index){
          console.log("The contents of the totals cell " + cell.innerText);
          totalCell = cell.innerText;
          attendantTotalCell = totalCell.replace(/[^0-9-.]/g, '');
          total = parseInt(attendantTotalCell) + parseInt(total);
          console.log("Attendant Total Cell is: " + attendantTotalCell);
          console.log("Attendant Total is " + total);
          cell.nextElementSibling.innerHTML = total;
        })
      }

If you add the following check to ensure that cell.nextElementSibling is defined, then this should resolve your problem: 如果添加以下检查以确保定义了cell.nextElementSibling ,那么这应该可以解决您的问题:

calculateRunningTotals(){
    var attendantTotalCell = 0;
    var total = 0;
    var totalCell="";
    var totalsCells = document.querySelectorAll("td:nth-child(3)");

    totalsCells.forEach(function(cell, index){
      console.log("The contents of the totals cell " + cell.innerText);
      totalCell = cell.innerText;
      attendantTotalCell = totalCell.replace(/[^0-9-.]/g, '');
      total = parseInt(attendantTotalCell) + parseInt(total);
      console.log("Attendant Total Cell is: " + attendantTotalCell);
      console.log("Attendant Total is " + total);

      /* Add the following check to ensure nextElementSibling is defined
         before attempting to access it */
      if(cell.nextElementSibling) {
        cell.nextElementSibling.innerHTML = total;
      }
    })
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法将属性'innerHTML'设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的Typeerror:无法将属性innerHTML设置为null - Uncaught Typeerror: Cannot set property innerHTML of null 未捕获的TypeError:无法将属性'innerHTML'设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法将属性'innerHTML'设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法设置null的属性'innerHTML' - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获(承诺)类型错误:无法读取 null 的属性“innerHTML”? - Uncaught (in promise) TypeError: Cannot read property 'innerHTML' of null? 未捕获(承诺)TypeError:无法设置 null 的属性“innerHTML” - 我可以在 console.log() 中看到值 - Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null - I can see value in console.log() 未捕获(承诺中)类型错误:无法设置 null 的属性(设置“innerHTML”) - Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerHTML') 未捕获的 promise。 无法设置属性。 onMovieSelect 上 null 的“innerHTML” - Uncaught promise. Cannot set property. 'innerHTML' of null at onMovieSelct 未捕获的TypeError:无法在phonegap中将属性'innerHTML'设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in phonegap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM