e.target.value 的值未定义
我有一个 let: valorImput,来自输入的 e.target.value 。 我使用该值将其与数组中的值进行比较,并且它有效。但是当我想获取它的值时,它说未定义,我无法在将来的函数中使用它。 这是 Codesand 的链接,包含整个内容代码。
let valorImput = "";
dropDown.onchange = (e) => {
valorImput = e.target.value;
console.log("dropdown onchange console", e.target.value);
};
btn.onclick = (e) => {
const existe = productos.find((x) => x.titulo === valorImput);
existe ? (precio = existe.precio) : console.log("NO hay Nada");
document.getElementById("valorDeSelect").value = precio;
Swal.fire("El precio esta expresado en Dolares!", "USD " + precio, "success");
console.log("valor input", valorImput);
};
I have a let: valorImput, coming from an e.target.value from input.
I use this value to compare it with a value in an array and it works. But when I want to get its value it said undefined and I'm not able to use it in future functions.
This is a link to Codesand with the whole code.
let valorImput = "";
dropDown.onchange = (e) => {
valorImput = e.target.value;
console.log("dropdown onchange console", e.target.value);
};
btn.onclick = (e) => {
const existe = productos.find((x) => x.titulo === valorImput);
existe ? (precio = existe.precio) : console.log("NO hay Nada");
document.getElementById("valorDeSelect").value = precio;
Swal.fire("El precio esta expresado en Dolares!", "USD " + precio, "success");
console.log("valor input", valorImput);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
变量
valorImput
必须在全局范围内声明(在任何“{}”括号之外)。jsfiddle
请参阅文档 了解更多详细信息。
Variable
valorImput
must be declared in global scope (outside of any "{}" brackets).jsfiddle
See the documentation for more detail.