小编Sam*_*uel的帖子

如果我将输入值存储在变量中,为什么它的值始终为空?

I\xe2\x80\x99m 试图value从我的<input>属性,以便稍后使用它从特定 API URL 获取数据。

\n\n

问题是我的<input>无论我输入什么内容,我的值始终为空。

\n\n

我尝试使用document.querySelector()document.getElementById(); 两者产生相同的结果。

\n\n
const searchBtn = document.querySelector("#searchBtn");\n//const inpuValue = document.querySelector("#inputField").value;\nconst inputValue = (document.getElementById("inputField")).value;\nconst testing = () => alert(inputValue);\n\nsearchBtn.addEventListener("click", testing);\n
Run Code Online (Sandbox Code Playgroud)\n\n

该警报仅显示为空白,但如果我在 HTML 字段中指定值,则它不会\xe2\x80\x99t。所以我想我\xe2\x80\x99m 触发了正确的按钮和<input>字段。(我使用是alert因为我的浏览器都没有向我显示console.log因为我的浏览器都没有在控制台中

\n

html javascript variables dom

3
推荐指数
1
解决办法
4585
查看次数

标签 统计

dom ×1

html ×1

javascript ×1

variables ×1