如果文本字段或本地存储包含数据,则自动提交表单
Automatic form submission if textfield or localstorage contains data
我想执行自动登录功能。我有一个脚本,它会在用户第一次登录时将电子邮件和密码保存在本地存储中,并且还会在用户随后在各自的文本字段(电子邮件和密码)中打开应用程序时显示电子邮件和密码
$(function() {
var
$email = $('#email'),
$password = $('#password');
// SAVE VARIABLES TO LOCAL STORAGE
$('form').on('submit', function() {
localStorage.setItem("eaddress", $email.val());
localStorage.setItem("pwd", $password.val());
});
// IF EMAIL AND PASSWORD ARE SAVED, PREPOPULATE THE FORM FIELDS
if (localStorage.getItem("eaddress") != null) {
$email.val(localStorage.getItem("eaddress"));
}
if (localStorage.getItem("pwd") != null) {
$password.val(localStorage.getItem("pwd"));
}
});
我的HTML
<form action="login_script.asp" method="post" name="form5" target="_parent" id="form5" onclick="save()" >
<table width="270" border="0" cellpadding="4" cellspacing="4">
<tr>
<td><strong>Email</strong></td>
</tr>
<tr>
<td>
<input name="email" type="email" id="email" size="40"/></td>
</tr>
<tr>
<td><strong>Password</strong></td>
</tr>
<tr>
<td>
<input name="password" type="password" id="password" size="40"/></td>
</tr>
<tr>
<td>
<input type="submit" id="submit" name="submit" value="Submit">
</td>
</tr>
<tr>
<td><span style="width: 480px; margin: 0 auto; margin-top: 30px;"><img src="imgs/loader.gif" alt="" name="gif" id="gif" style="display: block; margin: 0 auto; width: 30px; visibility: hidden;" /></span></td>
</tr>
</table>
</form>
<script type="text/javascript">
$('#form5').submit(function() {
$('#gif').css('visibility', 'visible');
return true;
});
</script>
现在我想要实现的是一旦本地存储中有数据或电子邮件和密码文本字段包含一些变量就应该自动提交
我得到了一项研究的脚本,该脚本可以自动提交表单,但不知道如何将其融合到我的研究中
$(function(){
$("input[name=name]").val("somename");
$("input[name=email]").val("323@ds.com");
$('#aweberform').submit();
});
<input type="submit" name="someothername" value="click to submit!">
像这样的东西应该可以工作:
$(function() {
var
$email = $('#email'),
$password = $('#password'),
localEmail = localStorage.getItem("eaddress"),
localPwd = localStorage.getItem("pwd");
// IF EMAIL AND PASSWORD ARE SAVED PREVIOUSLY, POPULATE THE FORM FIELDS THEN SUBMIT FORM
// check if email saved previously
if (localEmail != null) {
$email.val(localEmail);
}
// check if password saved previously
if (localPwd != null) {
$password.val(localPwd);
}
// if both exist in localstorage, submit form
if (localPwd != null && localPwd != null) {
$('form').submit();
}
// SAVE VARIABLES TO LOCAL STORAGE
$('form').on('submit', function() {
localStorage.setItem("eaddress", $email.val());
localStorage.setItem("pwd", $password.val());
});
});
我想执行自动登录功能。我有一个脚本,它会在用户第一次登录时将电子邮件和密码保存在本地存储中,并且还会在用户随后在各自的文本字段(电子邮件和密码)中打开应用程序时显示电子邮件和密码
$(function() {
var
$email = $('#email'),
$password = $('#password');
// SAVE VARIABLES TO LOCAL STORAGE
$('form').on('submit', function() {
localStorage.setItem("eaddress", $email.val());
localStorage.setItem("pwd", $password.val());
});
// IF EMAIL AND PASSWORD ARE SAVED, PREPOPULATE THE FORM FIELDS
if (localStorage.getItem("eaddress") != null) {
$email.val(localStorage.getItem("eaddress"));
}
if (localStorage.getItem("pwd") != null) {
$password.val(localStorage.getItem("pwd"));
}
});
我的HTML
<form action="login_script.asp" method="post" name="form5" target="_parent" id="form5" onclick="save()" >
<table width="270" border="0" cellpadding="4" cellspacing="4">
<tr>
<td><strong>Email</strong></td>
</tr>
<tr>
<td>
<input name="email" type="email" id="email" size="40"/></td>
</tr>
<tr>
<td><strong>Password</strong></td>
</tr>
<tr>
<td>
<input name="password" type="password" id="password" size="40"/></td>
</tr>
<tr>
<td>
<input type="submit" id="submit" name="submit" value="Submit">
</td>
</tr>
<tr>
<td><span style="width: 480px; margin: 0 auto; margin-top: 30px;"><img src="imgs/loader.gif" alt="" name="gif" id="gif" style="display: block; margin: 0 auto; width: 30px; visibility: hidden;" /></span></td>
</tr>
</table>
</form>
<script type="text/javascript">
$('#form5').submit(function() {
$('#gif').css('visibility', 'visible');
return true;
});
</script>
现在我想要实现的是一旦本地存储中有数据或电子邮件和密码文本字段包含一些变量就应该自动提交
我得到了一项研究的脚本,该脚本可以自动提交表单,但不知道如何将其融合到我的研究中
$(function(){
$("input[name=name]").val("somename");
$("input[name=email]").val("323@ds.com");
$('#aweberform').submit();
});
<input type="submit" name="someothername" value="click to submit!">
像这样的东西应该可以工作:
$(function() {
var
$email = $('#email'),
$password = $('#password'),
localEmail = localStorage.getItem("eaddress"),
localPwd = localStorage.getItem("pwd");
// IF EMAIL AND PASSWORD ARE SAVED PREVIOUSLY, POPULATE THE FORM FIELDS THEN SUBMIT FORM
// check if email saved previously
if (localEmail != null) {
$email.val(localEmail);
}
// check if password saved previously
if (localPwd != null) {
$password.val(localPwd);
}
// if both exist in localstorage, submit form
if (localPwd != null && localPwd != null) {
$('form').submit();
}
// SAVE VARIABLES TO LOCAL STORAGE
$('form').on('submit', function() {
localStorage.setItem("eaddress", $email.val());
localStorage.setItem("pwd", $password.val());
});
});