javascript - jQuery 表单处理问题

标签 javascript jquery html

我在使用 jQuery 处理 html 表单中的数据时遇到问题。我有这个简单的表格:

<form id="singup">
  <input type="text" placeholder="Full Name" id="signup-name">
  <input type="email" placeholder="Email Address" id="signup-email">
  <input type="password" placeholder="Password" id="signup-pass">
  <input type="password" placeholder="Retype Password" id="signup-retype-pass">
  <button class="button-hover" type="submit" id="signup-submit">Create account now</button>
</form>

现在我想使用 jQuery 获取输入的值。

$("#singup").submit(function (e) {
    var email = $('#singup-email').val();
    console.log(email);
    e.preventDefault(e);
});

但是浏览器控制台告诉我 var email 未定义。为什么?

感谢您的帮助!

最佳答案

打字错误。使用signup-email而不是singup-email

$("#singup").submit(function (e) {
    var email = $('#signup-email').val();
    console.log(email);
    e.preventDefault(e);
});

关于javascript - jQuery 表单处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49316048/

相关文章:

javascript - jQuery if 语句破坏了我的代码

javascript - Zooz 支付网关在 JS 中集成

html - 在所有现代浏览器中获得相同的阴影(IE 版本 9 除外)

javascript - jQuery 相当于 getElementbyName 不起作用

javascript - 当 WebView 位于 ScrollView 内时,ScrollTo() 方法不起作用

javascript - 调整页面大小后固定导航栏问题

JavaScript:计算字符串中特定整数的实例

html - 在 Windows8-Arm 上禁用 IE11 中的所有页面缩放

html - 我应该在我的网站上使用类似 sprite 的缩略图技术吗?

javascript - 防止在定时在线测验中作弊