e.target.value 的值未定义

发布于 2025-01-19 06:18:20 字数 790 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗫嚅 2025-01-26 06:18:20

变量 valorImput 必须在全局范围内声明(在任何“{}”括号之外)。

jsfiddle

请参阅文档 了解更多详细信息。

Variable valorImput must be declared in global scope (outside of any "{}" brackets).

jsfiddle

See the documentation for more detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文