Home  >  Article  >  Web Front-end  >  基于jquery的simpleValidate简易验证插件_jquery

基于jquery的simpleValidate简易验证插件_jquery

WBOY
WBOYOriginal
2016-05-16 17:01:451184browse

如果你不需要做onfocus和onblur的即时验证,如果你不想对每个表格都通过JS定义验证规则,如果你只需要在提交的时候进行一次验证和反馈,如果你喜欢简约的代码结构,我觉得simpleValidate是不错的选择。

从关注度和下载量来看,这插件并不怎么受欢迎,不过不要紧,它是我的菜。
下载地址在最下边,开源的,DEMO很详细,相当容易上手。
原版不支持IE,原因是JSON的逗号和length是保留字的问题,修复方法就是把所有“}”前不必要的逗号删掉,变量length改用其他变量名,我改了一个,并对提示内容进行了汉化,目前正在使用,暂未发现其他BUG,下载地址:jquery.simple.validation.js

定义 data-rules 属性:
用井号“#”区分多个验证规则,用加号“+”附带验证对比值,用横杠“-”附带反馈项目标题,以下列一下基本写法

复制代码 代码如下:




定义所有form在提交前都进行验证:

复制代码 代码如下:

$('form').bind('submit',function(){
    var message=$(this).validate();
    if(message!==true){
        alert(message);
        return false;
    }
    return true;
});

项目开源地址:https://github.com/capucinno-lee/jquery-simple-validation
DEMO地址:http://demo.jb51.net/js/2014/jquery_simple_validation/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn