以下是我为验证密码而创建的功能。在验证有效的同时,下一个函数link()将覆盖它并继续进行,而不考虑验证。
<script>
// insert validation on signup and login forms here
// password validation variables
function validatePassword() {
var pswrd = document.getElementById("pswrd").value;
var pswrdrpt = document.getElementById("pswrdrpt").value;
pswrd.onchange = validatePassword;
pswrdrpt.onkeyup = validatePassword;
if(pswrd == "" || pswrd == null) {
alert("incorrect input");
return;
} else {
}
// if(pswrd != pswrdrpt) {
// alert("Passwords don't match");
// return;
// } else (pswrd =""){
// alert("Incorrect input");
// } else {
// }
// pswrd.onchange = validatePassword;
// pswrdrpt.onkeyup = validatePassword;
}
function link() {
// alert(1);
// if(!validatePassword()) {
// return;
// } else {
window.location.href = "homepage.html";
}
// This where you pick it up from
</script>
以下是link()应该执行的形式的代码-
<form class="modal-content animate" method = "POST" action = "link()"> <!-- Same as above, just testing action -->
<div class="container">
<h1>Sign up</h1>
<p>Please fill this form to join us on the other side</p>
<hr>
<label for="Username"><b>Username</b></label>
<input id="usrnm" type="text" placeholder="Use your creativity" name="Username" required/>
<label for="psw"><b>Password</b></label>
<input id="pswrd" type="password" minlength="4" placeholder="Keep it simple please" name="psw" required/>
<label for="pswRepeat"><b>Repeat Password</b></label>
<input id="pswrdrpt" type="password" placeholder="Again" name="pswRepeat" onblur="validatePassword()" required/>
<label>
<input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px">Remeber me!
</label>
<p> By creating an account you agree to up your level of awesome!</p>
<div class="clearfix">
<button type="button" onclick="document.getElementById('signUp').style.display='none'" class="cancelbtn">?????</button>
<button type="submit" onclick="link()" class="signupbtn">Hook me up fam</button>
</div>
</div>
</form>
除非不是。我还在页面末尾使用了一些jQuery插件,如果我发表评论,它们会引至this page with the jQuery alongside it
请让我知道我能做什么,谢谢您的时间和帮助。