[英]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.