1 <!DOCTYPE html>
2 <html lang="en">
3
4 <head>
5 <meta charset="UTF-8">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta http-equiv="X-UA-Compatible" content="ie=edge">
8 <script src="https://cdn.bootcss.com/require.js/2.3.5/require.js"></script>
9 <title>Document</title>
10 </head>
11
12 <body>
13
14 <button id="require">點擊require肯定啊</button>
15
16 <script>
17 require.config({ 18 // 當前目錄
19 baseUrl: "./", 20
21 // 定義js,不用寫後綴js
22 paths: { 23 "jquery": "http://code.jquery.com/jquery-2.1.1.min"
24 }, 25
26 // 請求等待時間
27 waitSeconds: 15
28 }); 29
30 // 使用jquery
31 require(["jquery"], 32 function (jquery) { 33 // 邏輯代碼
34 $('#require').on('click',function(){ 35 console.log('hehei'); 36 }); 37 } 38 ); 39 </script>
40 </body>
41
42 </html>
至於,咱們爲何用require.js(大概也就是js阻塞做用的緣由吧,一旦某些JavaScript代碼出現異常,頁面確定加載的很好看)css
更多參數,參考官網API:http://www.requirejs.cn/html