收藏
回答

addEventListener为null问题

框架类型 问题类型 操作系统 工具版本
小游戏 Bug Windows 1.01.1805150

let resource = null

   return new Promise((resolve,reject)=>{

     resourcesList.forEach(resName => {


       if (resName.endsWith('.png')) {

         resource = new Image()

         resource.src = 'images/${resName}'


       } else if (resName.endsWith('.mp3')) {

         resource = new Audio()

         resource.src = 'audio/${resName}'


       }


       resource.addEventListener('load', () => {

         loadedCount++

         }

       })

显示TypeError: Cannot read property 'addEventListener' of null,

求大佬帮debug


回答关注问题邀请回答
收藏

2 个回答

  • 吾独寒钓临江雪
    吾独寒钓临江雪
    2022-08-25

    我这个resName.endsWith('.png')直接报错了,TypeError: resName.endsWith is not a function。我直接服气了,什么问题啊?为什么不能用endsWith()?

    2022-08-25
    有用
    回复
  • 亚苏
    亚苏
    2018-11-16

    没走进if和else if呗

    2018-11-16
    有用
    回复 2
    • 叮个哩个啷
      叮个哩个啷
      2018-11-16

      已经解决了,走进了的


      2018-11-16
      回复
    • 2019-09-18回复叮个哩个啷
      请问什么问题,怎么解决的
      2019-09-18
      回复
登录 后发表内容