我对jQuery很新,遇到了一些麻烦。我的项目有一个使用表单的登录/注册页面,并且仅限于使用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>
答案 0 :(得分:0)
从我可以收集到的内容中,查看您的代码(我在这里使用您的代码https://jsfiddle.net/webbm/edfwoxxh/制作了一个小提琴),您正在尝试使用id {{{{}}对表单的输入进行某种检查。 1}}
如果您更改代码以使用此代码,则仅在注册时提交正确的功能:
localStorageTest
你需要在$('#localStorageTest').submit(function() {
/* Your code here */
});
之外做一些其他事情,因为这没有用。如果要检查输入的值,可以执行以下操作:
$('.stored').keyup