使用方式很简单,简单测试代码如下:

<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:

[1] errorPlacement自定义后其他不显示

[2] 官网文档

http://www.iteye.com/problems/85374

jQuery Validation Plugin的更多相关文章

  1. jQuery Validation Plugin学习

    http://blog.csdn.net/violet_day/article/details/14109261 jQuery Validation Plugin Demo 一.默认校验规则 (1)r ...

  2. (转)jQuery Validation Plugin客户端表单证验插件

    jQuery Validation Plugin客户端表单验证插件 官方文档:http://jqueryvalidation.org/documentation/ 官方demo:http://jque ...

  3. 表单验证的validate.js插件---jQuery Validation Plugin

    早上在公交车上看了一个关于慕课网的教程<表单验证的validate.js插件---jQuery Validation Plugin>,正好可以用到自己近期开发简易微博的注册页面和登录页面, ...

  4. jquery validation plugin 使用

    <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Prope ...

  5. jQuery Validation remote的缓存请求

    不知大家有没有遇到,用jQuery Validation(本文讨论的版本为jQuery Validation Plugin 1.11.1)用remote方式做校验时,如果验证元素的值保持一致,进行多次 ...

  6. JQuery 表单验证--jquery validation

    jquery validation,表单验证控件 官方地址 :http://jqueryvalidation.org/ jquery表单验证 默认值校验规则 jquery表单验证 默认的提示 < ...

  7. jQuery Validation让验证变得如此easy(一)

    一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...

  8. jQuery Validation让验证变得如此容易(一)

    一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...

  9. Jquery Validation 验证控件的使用说明

    转载自:http://blog.csdn.net/huang100qi/article/details/52453970,做了一些简化及修改 下载地址:https://jqueryvalidation ...

随机推荐

  1. Storm 系列(二)实时平台介绍

    Storm 系列(二)实时平台介绍 本章中的实时平台是指针对大数据进行实时分析的一整套系统,包括数据的收集.处理.存储等.一般而言,大数据有 4 个特点: Volumn(大量). Velocity(高 ...

  2. 关于apicloud图片缓存

    imageCache如果是同一个地址,得到的缓存文件名字是一样的.可能是对url md5了一下. apicloud目前有两种清除方式1 一种是api.clearCache   另一种方法当然是强大的 ...

  3. 2018.10.19 NOIP训练 变化的序列(线性dp)

    传送门 f[i][j]f[i][j]f[i][j]表示后iii个对答案贡献有jjj个a的方案数. 可以发现最后a,ba,ba,b的总个数一定是n∗(n−1)/2n*(n-1)/2n∗(n−1)/2 因 ...

  4. arduino 串口命令解析

    /* DS3231_test.pde Eric Ayars 4/11 Test/demo of read routines for a DS3231 RTC. Turn on the serial m ...

  5. C++标准模板库(STL)和容器

    1.什么是标准模板库(STL)? (1)C++标准模板库与C++标准库的关系 C++标准模板库其实属于C++标准库的一部分,C++标准模板库主要是定义了标准模板的定义与声明,而这些模板主要都是 类模板 ...

  6. python编码(二)

    谈谈Unicode编码,简要解释UCS.UTF.BMP.BOM等名词 问题一 使用Windows记事本的“另存为”,可以在GBK.Unicode.Unicode big endian和UTF-8这几种 ...

  7. day4之内置函数、匿名函数,递归函数

    内置函数: https://www.processon.com/view/link/5adc6062e4b04721d63171eb?pw=3218 匿名函数:lambda lambda 语法: la ...

  8. 编译hbase-1.2.3源代码

    目录 目录 1 1. 约定 1 2. 安装jdk 1 3. 安装maven 1 4. 网络配置 2 4.1. eclipse 3 4.2. maven 3 5. 从hbase官网下载源代码包: 4 6 ...

  9. (匹配 最小路径覆盖)Air Raid --hdu --1151

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  10. Robotframework 之常用断言关键字简介

    任何自动化测试框架或实例中断言是必不可少的,Robotframework同样如此,那下面就介绍下其常用断言关键字. 1.Should Be Empty   判断是否为空,如果不为空,执行失败,示例: ...