关于jquery-validation-1.11.1插件
我使用了“jquery-validation-1.11.1插件”来检查注册表表单的数据验证。它是一个好的、有用的插件。完整的代码在这里关于jquery-validation-1.11.1插件,jquery,jquery-validate,Jquery,Jquery Validate,我使用了“jquery-validation-1.11.1插件”来检查注册表表单的数据验证。它是一个好的、有用的插件。完整的代码在这里 <html> <head> <title>Data validation with jquery plug-in</title> <style> label{ display:block; color: #555;
<html>
<head>
<title>Data validation with jquery plug-in</title>
<style>
label{
display:block;
color: #555;
margin-left:500px;
}
label.error{
color: #900;
font-style: Italic;
}
input{
margin-left:500px;
}
textarea{
margin-left:500px;
}
</style>
</head>
<body>
<form id="comment" action="">
<p>
<label for="cname">Name(required, at least 2 characters)</label>
<input id="cname" name="name">
</p>
<p>
<label for="cemail">Name(required)</label>
<input id="cemail" name="email" type="email">
</p>
<p>
<label for="curl">URL(optional)</label>
<input id="curl" name="url" type="url">
</p>
<p>
<label for="comment">Your comment(required)</label>
<textarea id="ccomment" name="comment"></textarea>
</p>
<p>
<input class="submit" type="submit" value="submit">
</p>
<p>
<input type="submit" value="Click">
</p>
</form>
<script src="jquery.js"></script>
<script src="jquery.validate.min.js"></script>
<script>
$(document).ready(function(){
$("#comment").validate({
rules:{
name:{
"required":true,
"min":2
},
email:{
"required":true,
"email":true
},
comment:{
"required":true
}
}
});
});
</script>
</body>
使用jquery插件进行数据验证
标签{
显示:块;
颜色:#555;
左边距:500px;
}
标签错误{
颜色:#900;
字体:斜体;
}
输入{
左边距:500px;
}
文本区{
左边距:500px;
}
名称(必填,至少2个字符)
姓名(必填)
URL(可选)
您的评论(必填)
$(文档).ready(函数(){
$(“#注释”).validate({
规则:{
姓名:{
“必需”:正确,
“最小”:2
},
电邮:{
“必需”:正确,
“电子邮件”:正确
},
评论:{
“必需”:true
}
}
});
});
我只想在单击“提交按钮”时检查验证。但现在我的问题是,当我点击任何按钮时,都要进行数据验证。我怎样才能修复它?试试这个
$('#myform').validate({
rules:{
name:{
"required":true,
"min":2
},
email:{
"required":true,
"email":true
},
comment:{
"required":true
}
},
submitHandler: function (form) { // for demo
alert('form submitted');
return false;
}
});
$('#register').on('click', function () {
$(this).closest('form').submit();
});
$('#home-page-submit').on('click', function () {
// home page called
alert('form cancelled');
location.href='home.html';
return false;
});
更改您的提交按钮
如下:
<p>
<input class="submit" type="submit" value="submit" id="register">
</p>
<p>
<input type="button" value="Click" id="home-page-submit">
</p>
</form>
请生成更准确的问题标题,并尝试重新格式化您的问题,因为它可以以多种方式理解。还包括您尝试/正在做的示例代码。为什么要使用表单提交按钮转到主页?使用常规的锚定链接。我已经生成了准确完整的代码示例。请检查一下并帮助我。
<input type="button" value="Go to home page"
onclick="window.location.href='home.html'" />