javascript - why my last.addEventListener("click",nextLevel) not working?
问题描述
https://codepen.io/demi-chen/pen/RwGPgxv
let last = theLeftSide.lastElementChild
last.addEventListener("click",nextLevel)
console.log(last) =====> it does show <img>......why the addEventListener not working
function nextLevel(){
event.stopPropagation();
numberOfFaces += 5;
generateFaces();
}
I try to find the lastElementChild in the first div. It does show ...... after I use console.log to check. why the addEventListener not working. I click the lastElementChild smile.png face but it's not working. if function nextLevel() is working. the left&right side should add more smile.png.
Tks!
解决方案
its quite a simple fix really change your nextlevel to
function nextLevel(event){
event.stopPropagation();
numberOfFaces += 5;
generateFaces();
}
推荐阅读
- python-3.x - 如何从multipledropdown相关列表中抓取所有选项值
- javascript - 在 Firefox 中,元素的位置在顶部和左侧偏移一个像素,在 Chrome 中是正确的
- ios - 如何在没有 RxSwift 的情况下快速观察 UserDefaults 数据?
- go - 如何在 DataStore 中存储 *time.Time 类型的结构字段的当前时间?
- java - 插入大量记录时,休眠持续丢失一些记录
- python - 创建一个仅包含列表的所有数字的子列表,直到它达到某个数字
- arrays - 在服务中调用 $http.get 时返回一个空数组
- vba - 限制项目不返回任何结果,只是 0
- java - javax.ws.rs.ProcessingException:找不到内容类型 application/json 和类型类的 MessageBodyReader
- javascript - 如何在香草 javascript 中实现 lodash _.throttle?