我正在使用jquery验证val
$("form[name='form1']").validate({
rules: {
username: "required",
email: "required",
plz: "required",
language: "required",
spedition: "required",
agreement: "required",
},
messages: {
username: "Please enter your username",
email: "Please enter valid email",
plz: "Please enter your plz",
language: "Please enter your language",
spedition: "Please enter your spedition",
agreement: "Please check your agreement",
},
我想如果用户没有输入用户名,那么只有该错误不会显示其他错误。无论条件如何失败,那么验证应在此时停止不检查其他条件
答案 0 :(得分:-1)
Please run this script on your system it is same as you want.thankyou
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
function validate()
{
var username =jQuery("#username").val();
alert(username);
var email =jQuery("#email").val();
var password =jQuery("#password").val();
if(username=='')
{
jQuery("#error").html("Please Enter Your Username");
return false;
}
if(email=='')
{
jQuery("#error").html("Please Enter Your Email Address");
return false;
}
if(password=='')
{
jQuery("#error").html("Please Enter Your Password");
return false;
}
else
{
return true;
}
return true;
}
</script>
</head>
<body>
<form method="post" onsubmit="return validate()">
<div id="error"></div>
<input type="text" name="username" id="username" placeholder="Enter username">
<input type="email" name="email" id="email" placeholder="Enter Email Address">
<input type="password" name="password" id="password" placeholder="Enter Password">
<input type="submit" name="submit" id="submit" value="Submit">
</form>
</body>
</html>