load-by-requirejs.html
1.3 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Load By RequireJS</title>
<link rel="stylesheet" href="demo.css">
</head>
<body>
<form id="form1" class="form">
<div class="form-item">
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
</div>
<div class="form-item">
<input type="password" name="password" data-rule="required;" placeholder="Password">
</div>
<div class="form-item">
<button type="submit">Submit</button>
</div>
</form>
<script src="https://cdn.jsdelivr.net/requirejs/2.1.22/require.min.js"></script>
<script>
requirejs.config({
baseUrl: '../',
paths: {
jquery: 'https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
validator: 'dist/local/zh-CN'
},
shim: {
validator: ['../dist/jquery.validator.js?css']
}
});
// Way 1: Use plugin methods
require(['jquery', 'validator'], function($){
$('#form1').validator({
timely: 2,
stopOnError: true,
theme: 'yellow_right'
});
});
// Way 2: Just include nice-validator
// require(['validator']);
// Way 3: Define a module dependency nice-validator
// define('some-module', ['jquery', 'validator'], function($){
// // some code
// });
</script>
</body>
</html>