File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ * js公共函数 表单验证非空
3+ * 注意:在使用本文件中函数的时候需要在加载本文件之前先加载jquery库文件
4+ *
5+ * @author :nongfeidan
6+ * @date :2015-04-03
7+ */
8+ // JavaScript Document
9+
10+ //把需要验证的input加上一个class,通过class获取需要验证的input,如下:
11+ var aVerifi = $ ( '.verification input' ) ; //获取所有的验证对象
12+ var aPrompt = $ ( '.verification span' ) ; //获取所有的提示信息对象
13+
14+ //获取焦点触发的事件,提示信息消失
15+ aVerifi . each ( function ( index ) {
16+ $ ( this ) . focus ( function ( ) {
17+ aPrompt . eq ( index ) . html ( '' ) ;
18+ } )
19+
20+ } )
21+ //光标离开触发的事件,如为空提示信息
22+ aVerifi . each ( function ( index ) {
23+ $ ( this ) . blur ( function ( ) {
24+ if ( aVerifi . eq ( index ) . val ( ) == '' )
25+ aPrompt . eq ( index ) . html ( '请填写信息' ) ;
26+ aPrompt . eq ( index ) . css ( 'color' , 'red' ) ;
27+ } )
28+
29+ } )
30+
31+ //表单提交事件,调用非空函数
32+ $ ( '#form' ) . submit ( function ( ) {
33+ return checkSubmit ( aVerifi , aPrompt ) ; // 第一个参数是判断非空的对象 ,第二个是提示信息
34+ } )
35+ //验证非空函数
36+ function checkSubmit ( obj1 , obj2 ) {
37+ var arr = [ ] ;
38+ obj1 . each ( function ( index ) {
39+ if ( obj1 . eq ( index ) . val ( ) == '' ) {
40+ obj2 . eq ( index ) . html ( '请填写信息' ) ;
41+ obj2 . eq ( index ) . css ( 'color' , 'red' ) ;
42+ }
43+ if ( obj1 . eq ( index ) . val ( ) !== '' ) {
44+ arr . push ( 1 ) ;
45+ }
46+
47+ } )
48+ if ( arr . length !== obj1 . length ) {
49+ return false ;
50+ }
51+ }
Original file line number Diff line number Diff line change 1- common.js ----- 工作中用到的公共js文件
1+ common.js ----- 工作中用到的公共js文件
22pic_lazyload_demo ----- 图片延时加载demo
3+ ValidateForm.js ----- 表单非空验证
You can’t perform that action at this time.
0 commit comments