[英]Why is jQuery .val() returning nothing?
I am trying to get the value of an input.我正在尝试获取输入的值。 Here is what my form looks like:
这是我的表格的样子:
This is the HTML for it:这是它的 HTML:
<label for="userName"></label>
<input type="text" class="form-input plain-text" id="userName" placeholder="Username">
Here is the jQuery to get its value and log it:这是 jQuery 获取其值并记录它:
$("#loginSubmit").click(function() {
var userName = $("#userName").val();
console.log(userName);
});
But when I type in some text and hit the login button that has the id #userName
, the console returns this:但是当我输入一些文本并点击 ID
#userName
的登录按钮时,控制台会返回:
Why does this not output dwedwed
in the console?为什么这不是 output
dwedwed
在控制台?
Thanks谢谢
Immediate reasons I can see are:我能看到的直接原因是:
Other than the above, its hard to determine what is going on without more code/information.除了上述之外,如果没有更多代码/信息,很难确定发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.