慕设计6337300
2018-08-19 15:03
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>表单验证插件</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://www.imooc.com/data/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="https://www.imooc.com/data/jquery.validate.js"></script>
<script type="text/javascript" src="https://www.imooc.com/data/jquery.validate.messages_cn.js"></script>
</head>
<body>
<form id="frmV" method="get" action="#">
<div id="divtest">
<div class="title">
<span class="fl">表单验证插件</span>
<span class="fr">
<input id="btnSubmit" type="submit" value="提交" />
</span>
</div>
<div class="content">
<span class="fl">邮箱:</span><br />
<input id="email" name="email" type="text" /><br />
<span class="tip"></span>
</div>
</div>
</form>
<script type="text/javascript">
$(function () {
$("#frmV").validate(
{
/*自定义验证规则*/
rules: {
email:{
required:true,
email:true
}
}
},
/*错误提示位置*/
errorPlacement: function (error, element) {
error.appendTo(".tip");
}
}
);
});
</script>
</body>
</html>
<!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> <title>表单验证插件</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="//www.imooc.com/data/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="//www.imooc.com/data/jquery.validate.js"></script> <script type="text/javascript" src="//www.imooc.com/data/jquery.validate.messages_cn.js"></script> </head> <body> <form id="frmV" method="get" action="#"> <div id="divtest"> <div class="title"> <span class="fl">表单验证插件</span> <span class="fr"> <input id="btnSubmit" type="submit" value="提交" /> </span> </div> <div class="content"> <span class="fl">邮箱:</span><br /> <input id="email" name="email" type="text" /><br /> <span class="tip"></span> </div> </div> </form> <script type="text/javascript"> $(function () { $("#frmV").validate( { /*自定义验证规则*/ rules: { email:{ required: true, email: true } }, /*错误提示位置*/ errorPlacement: function (error, element) { error.appendTo(".tip"); }, submitHandler: function(form) { // some other code // maybe disabling submit button // then: alert("邮箱验证成功!") // $(form).submit(); } } ); }); </script> </body> </html>
改成上面这样应该就行了
我终于知道哪里错了
rules: { email:{ required:true, email:true } } },
你们看,这里多了一个右括号
action这个属性就是跳转到某页面的URL,只是这里没填链接,填井号表示默认本页面
action="#", 这个#好像就是会跳到当前页面
jQuery基础(五)一Ajax应用与常用插件
69100 学习 · 400 问题
相似问题