未捕获的TypeError:无法读取属性“ innerHTML”

时间:2019-05-27 10:47:33

标签: javascript

我正在添加表值,但是遇到错误-

  

“未捕获的TypeError:无法读取未定义的属性'innerHTML'”

请帮助

var table = document.getElementById("paidfee"),
  sumVal = 0;
for (var i = 1; i < table.rows.length; i++) {
  sumVal = sumVal + parseInt(table.rows[i].cells[2].innerHTML);
}
document.getElementById("val").innerHTML = "Sum Value = " + sumVal;
console.log(sumVal);
<table id="paidfee" border=1>
  <tbody>
    <tr>
      <th>Receipt No</th>
      <th>Date</th>
      <th>Amount</th>
    </tr>
    <tr>
      <td>283</td>
      <td>30-03-2019</td>
      <td>2000</td>
    </tr>
    <tr>
      <td>319</td>
      <td>22-03-2019</td>
      <td>1000</td>
    </tr>
  </tbody>
</table>
<table>
  <tr>
    <td> <span id="val"></span>
</table>

0 个答案:

没有答案