gpt4 book ai didi

javascript - 无法读取 null 的属性 'addEventListener'(JavaScript Sails 应用程序)

转载 作者:行者123 更新时间:2023-12-03 06:29:27 25 4
gpt4 key购买 nike

我正在 sails 应用程序中尝试使用以下 onsip JavaScript 代码来应用视频通话,但出现错误:

Cannot read property addEventListener' of null

下面是它的 JavaScript 代码:

button.addEventListener('click', function() {
// Was on a call, so the button press means we are hanging up
if (onCall) {
onCall = false;
button.firstChild.nodeValue = 'video';
remoteRender.style.visibility = 'hidden';
session.bye();
session = null;
}
// Was not on a call, so the button press means we are ringing someone
else {
onCall = true;
button.firstChild.nodeValue = 'hang up';
remoteRender.style.visibility = 'visible';
session = makeCall(userAgent, target,
false, true,
remoteRender, null);
session.on('bye', function() {
onCall = false;
button.firstChild.nodeValue = 'video';
remoteRender.style.visibility = 'hidden';
session = null;
});
}
});

上述 HTML 代码为:

<button id="alice-video-button" class="right" type="button">video</button>

最佳答案

据我所知,此错误:“无法读取 null 的属性“addEventListener””

如果您在代码中的任何位置收到此错误,则需要检查 id 和选择器。

button.addEventListener('click', function () {..}

您可能会在这一行收到错误,并检查此“按钮”变量是否已设置。

希望这会有所帮助

关于javascript - 无法读取 null 的属性 'addEventListener'(JavaScript Sails 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38504976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com