简体   繁体   English

无法读取 null 的属性“addEventListener”(JavaScript Sails App)

[英]Cannot read property 'addEventListener' of null (JavaScript Sails App)

I am trying the below JavaScript code of onsip in sails app to apply video call, but it gives the error:我正在尝试使用sails应用程序中的onsip的以下JavaScript代码来应用视频通话,但它给出了错误:

Cannot read property addEventListener' of null无法读取 null 的属性 addEventListener'

Below is the JavaScript code for it:下面是它的 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 code for the above is:上面的 HTML 代码是:

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

As i know about this error : " Cannot read property 'addEventListener' of null"据我所知,此错误:“无法读取 null 的属性‘addEventListener’”

if you get this error any where in your code, you need to check about id's and selectors.如果您在代码中的任何地方遇到此错误,则需要检查 id 和选择器。

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

Probably you get your error on this line and check this "button" variable is set.可能您在这一行遇到错误并检查此“按钮”变量是否已设置。

Hope this will help希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取 null 的属性“addEventListener” - JavaScript - Cannot read property 'addEventListener' of null - JavaScript Javascript 无法读取 null 错误的属性“addEventListener” - Javascript Cannot read property 'addEventListener' of null errors JavaScript中“无法读取null的属性&#39;addEventListener&#39;”错误 - “Cannot read property 'addEventListener' of null” error in javascript 无法读取 null 的 addEventListener 的属性 - Cannot Read the property of addEventListener of null 无法读取 null 的属性“addEventListener” - Cannot read property 'addEventListener' of null 无法读取 null 的属性 addEventListener - Cannot read property addEventListener of null 添加EventListener JavaScript时“无法读取null的属性addEventListener” - "Cannot read property addEventListener of null" when adding EventListener JavaScript 未捕获的TypeError:无法在JavaScript Webshare API中读取null的属性“ addEventListener” - Uncaught TypeError: Cannot read property 'addEventListener' of null in JavaScript webshare api 无法在反应中使用 javascript 读取 null 的属性“addEventListener”? - Cannot read property 'addEventListener' of null using javascript in react? 为什么我无法读取 null javascript 的属性“addEventListener” - why i am getting Cannot read property 'addEventListener' of null javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM