它表示TypeError:document.getElementById(...)为空 [英] It says that TypeError: document.getElementById(...) is null

查看:179
本文介绍了它表示TypeError:document.getElementById(...)为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个演示页面。虽然我把一个参数推送到getElementById我不知道这是从哪里来的?当点击播放器播放列表图像时,Firebug会发出此错误。另外错误并没有发生一次,但是当我离开页面时,它重复了数千次。

I have a demo page. Althought I pushed a parameter to getElementById I wonder from where is this 'is null' error coming from? Firebug gives this error when one clicks the playlist images under player. Also the error did not happen only once, but it repeated thousands and thousands of time as I left the page open.

TypeError: document.getElementById(...) is null
[Break On This Error]   

document.getElementById(elmId).innerHTML = value;

Line 75  

除此之外,我想知道为什么标题和时间不显示,除非我点击这些播放列表图片之一?

In addition to this i wonder why title and time did not show unless I click one of these playlist pictures?

推荐答案

所有这些结果都在 null

document.getElementById('volume');
document.getElementById('bytesLoaded');
document.getElementById('startBytes');
document.getElementById('bytesTotal');

您需要在updateHTML中执行null检查,如下所示:

You need to do a null check in updateHTML like this:

function updateHTML(elmId, value) {
  var elem = document.getElementById(elmId);
  if(typeof elem !== 'undefined' && elem !== null) {
    document.getElementById(elmId).innerHTML = value;
  }
}

这篇关于它表示TypeError:document.getElementById(...)为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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