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 ...
随机推荐
- Debian Buster 配置 Laravel 运行环境(nginx + redis + supervisor)
1 目标 将开发完成的 Laravel 项目布署于 Debian 之上.由于项目要求使用 horizon 官方扩展,要求 PHP7.1+,故采用 Debian buster (下一版) 2 材料 IP ...
- python之基础补充
一 bit,和bytes的关系 bit:就是计算机的最小的表示单位. bytes:就是计算机的最小的储存单位. 1 字节(bytes) = 8 位(bit) 格式: print(bytes('字符' ...
- 33. Pay Gap for the Brightest Female Graduatea 最聪明的大学女毕业生面临的工资差距
33. Pay Gap for the Brightest Female Graduatea 最聪明的大学女毕业生面临的工资差距 ① When young women were found to ma ...
- Django入门与实践-第20章:QuerySets(查询结果集)(完结)
http://127.0.0.1:8000/boards/1/ #boards/models.py from django.utils.text import Truncator class Topi ...
- VBA替换函数
Sub test() On Error Resume Next Dim arr1, arr2, i, j arr1 = Range("T1:EI3") arr2 = Range(& ...
- Quartus调用MOdelsim仿真过程
quarutsii调用modelsim实际是相对比较简单的.因为不需要选择要编译的库. 调用前的设置:设置调用的工具,也就是下面的Tool name,选择仿真语言,在这里选择为Verilog HDL, ...
- (二)spring-mvc-showcase 和 swagger-springmvc 的恩恩怨怨
1. 搜索 spring showcase 就可以找到这篇 http://spring.io/blog/2010/07/22/spring-mvc-3-showcase 就是教你如何使用spring ...
- noip第8课作业
1. 计算书费 [问题描述]下面是一个图书的单价表: 计算概论 28.9 元/本 数据结构与算法 32.7 元/本 数字逻辑 45.6元/本 C++程序设计教程 78 元/本 人工智能 35 ...
- Sometimes , less is more
给小团队的特别建议 小团队的普遍现象在于人力紧张,不管是在创业公司还是在大公司内.对于不写代码就手痒的技术人员,如果再在技术上有点儿完美主义情节,那真是可以为代码鞠躬尽瘁的.稍微一整理,事情恨不得已经 ...
- Intellij IDEA 14的注册机(Java版)
import java.math.BigInteger; import java.util.Date; import java.util.Random; import java.util.zip.CR ...