-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvalidity.html
69 lines (68 loc) · 1.86 KB
/
validity.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>h5form</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="build/h5form.js"></script>
</head>
<body>
<form>
<p>
<input type="number" required min="0" max="10" step="0.5">
</p>
<p>
<input type="text" required placeholder="这里是必填项">
</p>
<p>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</p>
<textarea placeholder="例:期望旅行日期,旅客人数,延住酒店或其它附加服务。" id="CruiseForm_other" name="CruiseForm[other]"></textarea>
<div contentEditable style="border: 1px solid #ccc; outline: none;">
<div contentEditable style="border: 1px solid #ccc; outline: none;"><br></div>
</div>
<p>
<input type="submit" formnovalidate value="input按钮提交不验证">
<input type="submit" value="input按钮提交并验证">
</p>
<button type="submit">button submit</button>
</form>
<script>
$(function(){
var ifr = document.createElement("iframe");
(document.body || document.documentElement).appendChild(ifr);
var ifrDoc = ifr.contentDocument || ifr.contentWindow.document;
ifrDoc.open();
ifrDoc.writeln("");
ifrDoc.close();
var ifrWin = ifr.contentWindow;
console.log("全局变量检查");
for(var i in window){
if(!(i in ifrWin)){
try {
console.log(i, window[i]);
} catch (ex){
}
}
}
ifr.parentNode.removeChild(ifr);
console.log("全局变量检查 done");
$("form").submit(function(e) {
if(this.checkValidity()){
alert("表单效验通过");
} else {
alert("表单效验失败");
}
});
});
</script>
</body>
</html>