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

标签 javascript angularjs node.js sails.js

我正在 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/

相关文章:

javascript - 通过 selectInput 操作图例 - rCharts 中的 multibarChart

javascript - jQuery 图表用 webpack 生成 "Uncaught TypeError: e.setTimeout is not a function"

javascript - 在同一页面上显示数组

angularjs - 强制 Protractor 等待种子数据加载

node.js - Meteor 和 Fibers/bindEnvironment() 是怎么回事?

javascript - javascript错误中的连接

javascript - 由2个不同的选择框触发的多重排序操作

javascript - 在组件本身之外渲染组件的一部分

node.js - Docker Node.js Cron

node.js - 错误 : Hostname/IP doesn't match certificate's altnames: