页面刷新或仅新页面时出现“未捕获的类型错误”...?

问题描述

当我导航到 HTML/EJS 页面时,以下代码大纲非常有效,它成功地使用传递给文档的图像填充了一些标签(以“group_”为前缀):

external.js:

addEventListener("load",seeds);

function seeds() {

//...stuff here to define variables and run a loop to populate the tags 

  //**ADD THE PHOTO...

  _item = document.createElement("img"); 
  _item.setAttribute("id","seed_" + _str);
  _item.setAttribute("src","/galleries/pix/" + _cat + "/" + _str);
  _item.setAttribute("alt","picture of " + _str);
  _item.setAttribute("max-width",'100%');
  document.getElementById("group_" + _tally).appendChild(_item);  //Uncaught TypeError (appendChild) here...ONLY on page 'refresh' or load page in a new tab...works fine the 'first' page load only...

  //**

//...more stuff that does not run after the "Uncaught TypeError" on 'reloads'

}

我的问题是,如果我执行页面“刷新”或导航以在新选项卡中再次加载页面...我收到“未捕获的类型错误:无法读取 null 的属性 'appendChild'”错误和脚本在那一点上失败。另一个奇怪的事情是,图像是按原样创建的,但是脚本的其余部分停止了功能。

似乎“加载”的事件侦听器第一次运行良好,但是在随后每次尝试加载页面时都会引发错误。后续页面加载是否可能需要其他一些事件侦听器?我不认为应该是这样。

非常感谢有关问题可能是什么的任何建议。我先谢谢你。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)