简体   繁体   English

如何解决,Uncaught TypeError: videopath.addEventListener is not a function?

[英]How to resolve, Uncaught TypeError: videopath.addEventListener is not a function?

I am calling a function on button click, but facing the issue of Uncaught我正在调用按钮单击函数,但面临未捕获的问题

TypeError: videopath.addEventListener is not a function.类型错误:videopath.addEventListener 不是函数。

My HTML file.我的 HTML 文件。

I wanted to send the exact file path in my case which is a video path.在我的情况下,我想发送确切的文件路径,即视频路径。

<div class="input-btn-container">
  <input class="input-box" id="videopath" type="file" />
  <div id="result"></div>
  <div class="btn-wrapper">
    <button class="renderbtn" onclick="runRender()">start</button>
  </div>
</div>

the function which I am calling here on calling this function getting error.我在此处调用此函数时调用的函数出错。


function runRender(){
  let client = "some functions";

  let videopath = document.getElementById('videopath').files[0].path;
  let result = document.querySelector('#result');

  // here I am getting error.
  videopath.addEventListener('input', () => {
    client.invoke("counter", videopath, (error, res) => {
      if(error) {
        console.error(error);
      } else {
        result.textContent = res;
      }
    });
  });

  videopath.dispatchEvent(new Event('input'));
}

There just needs a modification in the runRender() which should be like.只需要在 runRender() 中进行修改即可。

function runRender(){
  let client = "some functions";

  let videopath = document.getElementById('videopath');
  let vedioPathValue = vediopath.files[0].path;
  let result = document.querySelector('#result');

  // here I am getting error.
  videopath.addEventListener('input', () => {
    client.invoke("counter", vedioPathValue , (error, res) => {
      if(error) {
        console.error(error);
      } else {
        result.textContent = res;
      }
    });
  });

  videopath.dispatchEvent(new Event('input'));
}

this is working fine for me.这对我来说很好用。

You are trying to add an event to a non-dom element and therefore you get this error, try this.您正在尝试向非 dom 元素添加事件,因此您收到此错误,请尝试此操作。

function runRender(){
    let client = "some functions";

    let videopath = document.getElementById('videopath').files[0].path;
    let videopathElment = document.getElementById('videopath');
    let result = document.querySelector('#result');

    // here I am getting error.
    videopathElment.addEventListener('input', () => {
        client.invoke("counter", videopath, (error, res) => {
            if(error) {
                console.error(error);
            } else {
                result.textContent = res;
            }
        });
    });
    videopathElment.dispatchEvent(new Event('input'));
}

Try this.尝试这个。

 function runRender() { let client = "some functions"; let videopath = document.getElementById('videopath'); let result = document.querySelector('#result'); // here I am getting error. videopath.addEventListener('input', () => { client.invoke("counter", videopath.value, (error, res) => { if (error) { console.error(error); } else { result.textContent = res; } }); }); videopath.dispatchEvent(new Event('input')); }
 <div class="input-btn-container"> <input class="input-box" id="videopath" type="file" /> <div id="result"></div> <div class="btn-wrapper"> <button class="renderbtn" onclick="runRender()">start</button> </div> </div>

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

相关问题 如何在JavaScript中修复“未捕获的TypeError:action.addEventListener不是函数” - How to fix “Uncaught TypeError: action.addEventListener is not a function” in JavaScript 如何解决Uncaught TypeError:undefined不是一个函数? - How to resolve Uncaught TypeError: undefined is not a function? 如何解决JavaScript中的“未捕获的TypeError:未定义不是函数”? - How to resolve “Uncaught TypeError: undefined is not a function” in javascript"? 如何解决Uncaught TypeError:对象不是函数? - How to resolve Uncaught TypeError: object is not a function? 如何解决此错误类型“未捕获的TypeError:(...)不是函数”? - How to resolve this error type 'Uncaught TypeError: (…) is not a function'? 未捕获的TypeError:check.addEventListener不是函数 - Uncaught TypeError: check.addEventListener is not a function JavaScript 未捕获类型错误:replay.addEventListener 不是 function - JavaScript Uncaught TypeError: replay.addEventListener is not a function 未捕获的类型错误:document.getElementsByClassName(...).addEventListener 不是函数 - Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function 未捕获的TypeError:Window.addEventListener不是函数 - Uncaught TypeError: Window.addEventListener is not a function 未捕获到的typeError:input.addEventListener不是函数 - Uncaught typeError : input.addEventListener is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM