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 ...
随机推荐
- Codeforces 665A. Buses Between Cities 模拟
A. Buses Between Cities time limit per test: 1 second memory limit per test: 256 megabytes input: s ...
- 在jmeter的beanshell中用java获取系统当前时间
import java.util.*; int y,m,d,h,mi,s; Calendar cal=Calendar.getInstance(); y=cal.get(Calendar.YEAR); ...
- eclipse 远程调试mapreduce
使用环境:centos6.5+eclipse(4.4.2)+hadoop2.7.0 1.下载eclipse hadoop 插件 hadoop-eclipse-plugin-2.7.0.jar 粘贴到 ...
- [GO]kafka的生产者和消费者
生产者: package main import ( "github.com/Shopify/sarama" "fmt" "time" ) ...
- docker镜像基本操作
操作镜像 使用 docker 命令行操作 docker 镜像 获取镜像 使用「docker pull +镜像名称」从网络上下载image镜像 core@localhost ~ $ docker pul ...
- json、JSONObject、JSONArray的应用
type.java package jiekou.duixiang; import java.text.ParseException;import java.text.SimpleDateFormat ...
- IntelliJ IDEA 2017版 spring-boot使用Spring Data JPA搭建基础版的三层架构
1.配置环境pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
- Unable to load tag handler class "com.showId.Id.ShowId" for tag "ShowId:ShowId"] with root cause错误的解决方案
严重: Servlet.service() for servlet [jsp] in context with path [/Biaoqian] threw exception [/1.jsp (l ...
- SGU 169 Numbers (找规律)
题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...
- LA 3708 && POJ 3154 Graveyard (思维)
题意:在周长为10000的圆上等距分布着n个雕塑,现在又加入m个,现在让m+n个等距分布,那就得移动一些原有的雕塑,问你移动的最少总距离是多少. 析:首先我们可以知道,至少有一个雕塑是可以不用移动的, ...