当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js报错 Cannot read property 'getAttribute' of null

js报错 Cannot read property 'getAttribute' of null

2019年09月27日  | 移动技术网IT编程  | 我要评论

页面echarts.js报错:uncaught typeerror: cannot read property 'getattribute' of null

echarts cannot read property 'getattribute' of null

根据报错信息查找原因发现是因为 实例化echarts的元素不存在,查看官方文档发现:

// 基于准备好的dom,初始化echarts实例
var mychart = echarts.init(document.getelementbyid('main'));

基于准备好的dom,初始化echarts实例,也就是只有 页面存在的html元素 才可以去初始化。

如果不知道页面是否存在此html元素,那么在 实例化echarts前 去打印一下看看

console.log(document.getelementbyid('main'))

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网