youtube-api removeEventListener无法正常工作 [英] youtube-api removeEventListener not working

查看:76
本文介绍了youtube-api removeEventListener无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以添加事件了.

addEventListener("onStateChange", "handleStateChange");

但尝试删除事件时不会.

but when trying to remove the event, it does not.

removeEventListener("onStateChange", "handleStateChange");

每当我暂停/播放视频时,仍会调用

handleStateChange .有没有人遇到这个问题并有解决方案?还是API上有错误?

handleStateChange is still being called whenever I pause/play the video. Has anyone run into this and have a solution? or is there a bug on the API?

推荐答案

我认为问题在于YouTube API的播放器对象没有 removeEventListener 方法.请记住,调用 addEventListener 时,您是将其作为构造的youtube播放器对象的一种方法,而不是使用定义为DOM元素的方法(YouTube API选择为其方法命名)为了使开发人员更熟悉而进行相同的操作).

I think the issue is that the player object of the YouTube API has no removeEventListener method. Keep in mind that when you call addEventListener, you are doing so as a method of the constructed youtube player object rather than using the one defined as a method of DOM elements (the YouTube API chooses to name their method the same in order to be more familiar for developers).

过去对其他人有用的一个建议是,当您处于可能需要删除事件侦听器的情况下,您只需重新定义状态更改回调即可……

One suggestion which has worked for others in the past is to, when you're in a situation that might need to remove the event listener, you instead just redefine your state change callback ... something like:

handleStateChange = function() {};

这篇关于youtube-api removeEventListener无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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