查询混淆提交按钮

query confusing submit buttons

我是 jQuery 的新手,遇到了一些麻烦。我的项目有一个使用表单的 login/register 页面,并且仅限于使用 localStorage。当我 运行 项目时,好像用于登录和注册的提交按钮被混淆了,尽管它们具有不同的 id 标签。我很困惑,我知道这个问题可能很愚蠢,但我已经搜索了几个小时,无法解决。如有任何帮助,我们将不胜感激!

html代码:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="welcome.js"></script>
</head>
<body>

<div data-role="page">
  <div data-role="header">
<h1>My Calendar</h1>
  </div>

  <div data-role="main" class="ui-content">
    <a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-btn-b ui-corner-all">Sign-in</a>

<div data-role="popup" id="myPopup" class="ui-content" style="min-width:250px;">

  <form method="post" action=" ">
  <div class="ui-field-contain">
    <label for="fullname">Full name:</label>
    <input type="text" name="fullname" id="fullname">       

    <label for="email">E-mail:</label>
    <input type="email" name="email" id="email" placeholder="Your email..">
  </div>
  <input id="submit" type="submit" data-inline="true" value="Submit">
</form>
</div>
  </div>


  <div data-role="main" class="ui-content">
<a href="#myPopup1" data-rel="popup" class="ui-btn ui-btn-inline ui-btn-b ui-corner-all">Sign-up</a>

<div data-role="popup" id="myPopup1" class="ui-content" style="min-width:250px;">

  <form id="localStorageTest" method="post" action=" ">
  <div class="ui-field-contain">
    <label for="fullname">Full name:</label>
    <input type="text" name="fullname" id="fullname" class = "stored">       

    <label for="email">E-mail:</label>
    <input type="email" name="email" id="email" placeholder="Your email.." class = "stored">
  </div>
  <input id= "submitcheck" type="submit" data-inline="true" value="Submit">
</form>
</div>
  </div>

</body>
</html>

jQuery:

$(document).ready(function () {

    if (localStorage["name"]&&localStorage["email"]) {
        window.location.href = "calendar.html";}
     else {$("<div>Incorrect Entry</div>").dialog();}



$('#localStorageTest').submitcheck(function() {
$('.stored').keyup(function () {
localStorage[$(this).attr('name')] = $(this).val();}
}); });
</script>

据我所知,查看您的代码(我在此处使用您的代码 https://jsfiddle.net/webbm/edfwoxxh/ 创建了一个 fiddle),您正在尝试对输入进行某种检查ID 为 localStorageTest

的表单

如果您更改代码以使用此功能,则仅当您在注册时提交时它会触发正确的功能:

$('#localStorageTest').submit(function() {
  /* Your code here */ 
});

你需要在其中做 $('.stored').keyup 以外的事情,因为那真的没有意义。如果你想检查输入的值,你可以这样做:

$('#localStorageTest').submit(function() {
  var fullname = $('#fullname').val();
  var email = $('#email').val();
  if(fullname) {
    //fullname has a value
  }
});