jQuery Validation Plugin
使用方式很简单,简单测试代码如下:
<html>
<head>
<script type="text/javascript" src="./jquery-1.7.2.js"></script>
<script type="text/javascript" src="./jquery.validate.1.11.js"></script>
</head>
<body>
<form id="myform">
<fieldset> <input type="text" required="required" name="description" id="description">
<button type="submit">Check</button>
</fieldset>
</form>
<script>window.onload = function() {
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#myform" ).validate({
rules: {
description: {
required: true,
maxlength: 4
}
}
});
};</script>
</body>
</html>
如果希望自定义提示信息的位置,使用errorPlacement参数,修改后,代码如下:
<html>
<head>
<script type="text/javascript" src="./jquery-1.7.2.js"></script>
<script type="text/javascript" src="./jquery.validate.1.11.js"></script>
</head>
<body>
<form id="myform">
<fieldset> <input type="text" required="required" name="description" id="description">
<button type="submit">Check</button>
</fieldset>
</form>
<script>window.onload = function() {
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#myform" ).validate({
errorPlacement: function(error, element) {
if (element.is(":radio"))
error.appendTo(element.parent());
else
error.insertAfter(element);
},
rules: {
description: {
required: true,
maxlength: 4
}
}
});
};</script>
</body>
</html>
其中errorPlacement中如果添加了修改,则需要if/else完整语句,因jquery.validation.js源码中,如果判断到已设置errorPlacement则按照其配置方式来处理。
所以,如果仅在errorPlacement中增加的if语句,而没有对其他条件(else)处理,则仅当满足if条件时显示提示信息,其他无法显示提示信息。
showLabel: function(element, message) {
//......
701 if ( this.settings.errorPlacement ) {
702 this.settings.errorPlacement(label, $(element) );
703 } else {
704 label.insertAfter(element);
705 }
//.....
}
Refs:
[2] 官网文档
http://www.iteye.com/problems/85374
jQuery Validation Plugin的更多相关文章
- jQuery Validation Plugin学习
http://blog.csdn.net/violet_day/article/details/14109261 jQuery Validation Plugin Demo 一.默认校验规则 (1)r ...
- (转)jQuery Validation Plugin客户端表单证验插件
jQuery Validation Plugin客户端表单验证插件 官方文档:http://jqueryvalidation.org/documentation/ 官方demo:http://jque ...
- 表单验证的validate.js插件---jQuery Validation Plugin
早上在公交车上看了一个关于慕课网的教程<表单验证的validate.js插件---jQuery Validation Plugin>,正好可以用到自己近期开发简易微博的注册页面和登录页面, ...
- jquery validation plugin 使用
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Prope ...
- jQuery Validation remote的缓存请求
不知大家有没有遇到,用jQuery Validation(本文讨论的版本为jQuery Validation Plugin 1.11.1)用remote方式做校验时,如果验证元素的值保持一致,进行多次 ...
- JQuery 表单验证--jquery validation
jquery validation,表单验证控件 官方地址 :http://jqueryvalidation.org/ jquery表单验证 默认值校验规则 jquery表单验证 默认的提示 < ...
- jQuery Validation让验证变得如此easy(一)
一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...
- jQuery Validation让验证变得如此容易(一)
一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...
- Jquery Validation 验证控件的使用说明
转载自:http://blog.csdn.net/huang100qi/article/details/52453970,做了一些简化及修改 下载地址:https://jqueryvalidation ...
随机推荐
- laravel中的old()函数
1.控制器 2.模板
- 【Sikuli】Sikuli 文档
http://sikulix-2014.readthedocs.io/en/latest/index.html
- 如何从dvi生成pdf--------亲测有效果.
用里面第二个命令. http://blog.csdn.net/u014682350/article/details/46482477
- 如果程序集是从 Web 上下载的,即使它存储于本地计算机,Windows 也会将其标记为 Web 文件,http://go.microsoft.com/fwlink/?LinkId=179545
使用Silverlight,经常弄出很多莫名的XXX文件来于Web,神马信任程序集,就Build个程序都那么麻烦,应该在所有发布时注明一些最基本的配置说明,最BT莫过于连下载程序集的地方都找不到. 若 ...
- 492. Construct the Rectangle
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- linux将程序扔到后台并获取程序的进程号
我们经常需要写一些执行时间较长的程序,但是如果在程序执行过程中超时了,有许多原因,可能是程序已经挂起了,这时就需要杀死这样的进程,则可以通过如下的命令执行: java -jar TestProcess ...
- 配置 cxf-ws spring bean 文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring bean加载2--FactoryBean情况处理
Spring bean加载2--FactoryBean情况处理 在Spring bean加载过程中,每次bean实例在返回前都会调用getObjectForBeanInstance来处理Factory ...
- vc中使用SendMessage正确发送自定义消息的方法
最近在用VC2008做开发,后来由于要用到消息的发送,而且需要自定义消息,在网上查找了很多例子,根据他们所说的,虽然大致都差不多,但是基本上没有 一个能完全做出来的.要知道VC编程有一个小地方出错,都 ...
- HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...