Uncaught Typeerror:无法读取null的属性'innerHTML' [英] Uncaught Typeerror: cannot read property 'innerHTML' of null

查看:1211
本文介绍了Uncaught Typeerror:无法读取null的属性'innerHTML'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释这些错误是什么吗?

Can anyone explain what is theses errors?


未捕获的TypeError:无法读取属性'innerHTML'的null

Uncaught TypeError: cannot read property 'innerHTML' of null

查看我的网站
这是导致错误的行:

View on my website This is the line which is causing the error:

var idPost=document.getElementById("status").innerHTML;

谢谢

推荐答案

var idPost=document.getElementById("status").innerHTML;

您的网页中不存在'status'元素。

The 'status' element does not exist in your webpage.

因此document.getElementById(status)返回null。虽然你不能使用NULL的innerHTML属性。

So document.getElementById("status") return null. While you can not use innerHTML property of NULL.

你应该添加这样的条件:

You should add a condition like this:

if(document.getElementById("status") != null){
    var idPost=document.getElementById("status").innerHTML;
}

希望这个答案可以帮到你。 :)

Hope this answer can help you. :)

这篇关于Uncaught Typeerror:无法读取null的属性'innerHTML'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆