我想用验证插件验证每个文本框。但我不知道我是否正确行事,我是这项技术的新手。有谁可以帮助我吗?
我想要做的是每当我删除特定文本框中的焦点时,如果其无效则显示错误消息,如果有效则显示“logo”。我希望它可以在每个文本框中完成。
这是我的代码。
$(document).ready(function(){
$("#valFname").hide();
$("#valLname").hide();
$('#mainform').validate({
rules: {
fname: {
required: true,
},
lname: {
required: true,
},
captcha: {
equalTo:"#key"
}
},
success: function () {
fname:
{
required: $("#valFname").show();
},
lname:
{
required: $("#valLname").show();
}
}
});
$('#btnSignUp').click(function () {
});
});
这是我的标记
<html>
<head>
<link rel="stylesheet" type="text/css" href="design.css">
<script type="text/javascript" src="jquery.js"></script>
<script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="loginBouncy.js"></script>
<script src="modal.js"></script>
<script type="text/javascript" src="validation.js"></script>
<script src="validate.js"></script>
<div id='mask' class='close_modal'></div>
<div id="signup" class='modal_window'>
<p id="summary"></p>
<img id="pane1" src="pane1.png"/>
<p id="label">SignUp</p>
<p id="label1">Personal Information</p>
<p id="label2">Account</p>
<p id="label3">Verification</p>
<hr id="hr1"/>
<form id="mainform" name="mainform" method="post" action="SignUp2.php">
<?php
session_start();
$_SESSION["code"] = md5(uniqid());
$_SESSION["key"] = substr($_SESSION["code"],0,5);
$key = $_SESSION["key"];
echo "<input style='z-index:12;' type='hidden' name='key' id='key' value='$key'/>";
?>
<img id="valFname" style="position:absolute; top:257px; z-index:20; left:835px;" src="valid.png"/><input type="text" id="fname" name="fname" placeholder="First Name"/>
<img id="valLname" style="position:absolute; top:257px; z-index:20; left:1045px;" src="valid.png"/><input type="text" id="lname" name="lname" placeholder="Last Name"/>
<input type="text" id="mname" name="mname" placeholder="M.I."/>
<input type="text" id="sadd" name="sadd" placeholder="Street"/>
<input type="text" id="tadd" name="tadd" placeholder="Town/City"/>
<input type="text" id="padd" name="padd" placeholder="Province/State"/>
<input type="text" id="user2" name="user2" placeholder="Your Username"/>
<input type="password" id="pass2" name="pass2" placeholder="Your Password">
<input id="captcha" name="captcha" type="text" placeholder="Insert Captcha">
<img id="imgcaptcha" src="captcha.php" /><br>
<input type="text" id="email" name="email" placeholder="Your Email"/>
<input type="submit" id="btnSignUp" value="" />
</input>
</form>
</div>
</html>