2个回答
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery/js/jquery-1.4.2.min.js"></script>
<script src="jquery-validate/jquery.validate.js"></script>
<script src="jquery-validate/lib/jquery.metadata.js"></script>
<script src="jquery-validate/localization/messages_cn.js"></script>
<script>
$(document).ready(function(){
$("#login").validate({
rules: {
username: {
required: true,
remote: {
url: "exist_User.php", //后台处理程序
type: "post", //数据发送方式
dataType: "json", //接受数据格式
data: { //要传递的数据
username:function(){
return $("#username").val();
}
}
}
},
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
},
confirm_password: {
required: true,
minlength: 6,
equalTo: "#password"
}
},
messages: {
username: {
required: "<span style='color:red'> 请输入用户名</span>",
minlength: jQuery.format("<span style='color:red'> 用户名不正确,应该在2个汉字或四个字符以上</span>")
},
email: {
required: "<span style='color:red''>请输入Email地址</span>",
email: "<span style='color:red'> 请输入正确的email地址</span>"
},
password: {
required: "<span style='color:red'> 请输入密码</span>",
minlength: jQuery.format("<span style='color:red'> 您输入的密码不正确,应该在6位或6位字符以上</span>")
},
confirm_password: {
required: "<span style='color:red'>请输入确认密码</span>",
minlength: jQuery.format("<span style='color:red'> 您输入的密码不正确,应该在6位或6位字符以上</span>"),
equalTo: "<span class='fred'>两次输入密码不一致</span>"
}
}
});
})
</script>
</head>
<body>
<form action="" method="post" id="login" name="login">
<label>用户名:</label><input name="username" id="username" type="text" />
<hr>
<label>邮件地址:</label><input name="email" type="text" />
<hr>
<label>密 码:</label><input id="password" name="password" type="password" />
<hr>
<label>确认密码:</label><input name="confirm_password" type="password" />
<hr>
<input name="userinfosub" type="submit" value="提交" />
</form>
</body>
</html>
exist_User.php 代码
<?php
if($_POST['username']!="ff"){
echo "true";
}else{echo "false"; }
?>
把插件引用正确就可以用了试试吧
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery/js/jquery-1.4.2.min.js"></script>
<script src="jquery-validate/jquery.validate.js"></script>
<script src="jquery-validate/lib/jquery.metadata.js"></script>
<script src="jquery-validate/localization/messages_cn.js"></script>
<script>
$(document).ready(function(){
$("#login").validate({
rules: {
username: {
required: true,
remote: {
url: "exist_User.php", //后台处理程序
type: "post", //数据发送方式
dataType: "json", //接受数据格式
data: { //要传递的数据
username:function(){
return $("#username").val();
}
}
}
},
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
},
confirm_password: {
required: true,
minlength: 6,
equalTo: "#password"
}
},
messages: {
username: {
required: "<span style='color:red'> 请输入用户名</span>",
minlength: jQuery.format("<span style='color:red'> 用户名不正确,应该在2个汉字或四个字符以上</span>")
},
email: {
required: "<span style='color:red''>请输入Email地址</span>",
email: "<span style='color:red'> 请输入正确的email地址</span>"
},
password: {
required: "<span style='color:red'> 请输入密码</span>",
minlength: jQuery.format("<span style='color:red'> 您输入的密码不正确,应该在6位或6位字符以上</span>")
},
confirm_password: {
required: "<span style='color:red'>请输入确认密码</span>",
minlength: jQuery.format("<span style='color:red'> 您输入的密码不正确,应该在6位或6位字符以上</span>"),
equalTo: "<span class='fred'>两次输入密码不一致</span>"
}
}
});
})
</script>
</head>
<body>
<form action="" method="post" id="login" name="login">
<label>用户名:</label><input name="username" id="username" type="text" />
<hr>
<label>邮件地址:</label><input name="email" type="text" />
<hr>
<label>密 码:</label><input id="password" name="password" type="password" />
<hr>
<label>确认密码:</label><input name="confirm_password" type="password" />
<hr>
<input name="userinfosub" type="submit" value="提交" />
</form>
</body>
</html>
exist_User.php 代码
<?php
if($_POST['username']!="ff"){
echo "true";
}else{echo "false"; }
?>
把插件引用正确就可以用了试试吧
展开全部
HTML部分
<form class="cmxform" id="commentForm" method="get" action="">
<p> <label for="cname">用户名(必需, 至少两个字符)</label> <input id="cname" name="name" class="required" minlength="2" /> <p>
<label for="cemail">邮箱(必需)</label> <input id="cemail" name="email" class="required email" /> </p>
<p> <label for="curl">URL(可选)</label> <input id="curl" name="url" class="url" value="" /> </p>
<p> <label for="ccomment">评论(必需)</label> <textarea id="ccomment" name="comment" class="required"></textarea> </p>
<p> <input class="submit" type="submit" value="Submit"/> </p>
</form>
javascript部分
$().ready(function() { $("#commentForm").validate(); });
<form class="cmxform" id="commentForm" method="get" action="">
<p> <label for="cname">用户名(必需, 至少两个字符)</label> <input id="cname" name="name" class="required" minlength="2" /> <p>
<label for="cemail">邮箱(必需)</label> <input id="cemail" name="email" class="required email" /> </p>
<p> <label for="curl">URL(可选)</label> <input id="curl" name="url" class="url" value="" /> </p>
<p> <label for="ccomment">评论(必需)</label> <textarea id="ccomment" name="comment" class="required"></textarea> </p>
<p> <input class="submit" type="submit" value="Submit"/> </p>
</form>
javascript部分
$().ready(function() { $("#commentForm").validate(); });
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询