-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo1.html
117 lines (117 loc) · 3.41 KB
/
demo1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
{% load staticfiles %}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>input check demo</title>
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
<script language="JavaScript" src="{% static 'InputCheck.js' %}" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
$(document).ready(function(e) {
$(':text').InputCheck({
defaultTemplate:'<b>{msg}</b>',//错误信息显示模板,{msg}会被替换为错误提示消息
validators:[{//检查器组,可以定义多个检查器
validator:function(v,e){//定义检查规则,v为输入框的值,e目录输入框对象,在此可对其进行操作。
return v>10;//返回结果必需为bool型
},
msg:'请输入大于10的数字',//错误提示信息
template:'<i>{msg}</i>'//也可以为每个检查器定义消息显示样式模板
},
{
validator:'phone',//可以使用内置检查器。其他内置检查器还有email,mobile,url,number等
msg:'请输入正确电话号码',
afterValidate:function(re){
if(!re){
this.error.addClass('greyfont');
}else{
this.error.removeClass('greyfont');
}
}
},
{
type:'ajax',//支持ajax异步验证
parameterName:'data',//传入参数名
url:'http://localhost:8000/polls/test/',
validator:function(v){//此时validator函数在ajax返回后调用,v为返回值(json格式)
return v.result=='true';
},
msg:'用户名重复'
}],
afterValidate:function(re){
if(!re){
this.error.addClass('redborder');
}else{
this.error.removeClass('redborder');
}
}
});
});
function check(){
alert($(':text').check());//也可外部调用
}
</script>
<style>
.page{width:100%}
.main{text-align:center; margin:20px auto; width:778px;}
.main table{margin:0 auto; float:left;}
.form {width:400px; margin:20px auto; text-align:center;}
.blackbackground {background-color:black;}
.greyfont {color:#CCC}
.redborder {border:1px solid #F00;}
.error{}
</style>
</head>
<body>
<div class="page">
<div class="main">
<div class="form">
<table border=0>
<tr>
<td>
标题1:
</td>
<td>
<input id="test" type="text" />
</td>
<td>
<span id="test-err" style="display:none;" class="error"></span>
<span id="test-loading" style="display:none; background-color:#F00">载入中……</span><br />
</td>
</tr>
<tr>
<td>
标题2:
</td>
<td>
<input id="test1" type="text" />
</td>
<td>
<span id="test1-err" style="display:none;" class="error"></span>
<span id="test1-loading" style="display:none; background-color:#0F0">载入中……</span><br />
</td>
</tr>
<tr>
<td>
标题3:
</td>
<td>
<input id="test2" type="text" />
</td>
<td>
<span id="test2-err" style="display:none;" class="error"></span>
<span id="test2-loading" style="display:none; background-color:#00F">载入中……</span><br />
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="提交" onclick="check();"/>
</td>
<td> </td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>