• RequireJS 插件


    网址:http://www.requirejs.cn/docs/api.html#i18n

    RequireJS的插件:

    Text:自动加载一些非js的文本文件。

    domReady:确保在Dom Ready之后,执行需要与DOM交互的逻辑。

    i18n : 语言的本地化

    目录结构:

    例子:

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="utf-8"/>                
     5         <title>Hello The World!</title>        
     6         <script data-main="js/main" src="js/require.js" ></script>    
     7     </head>
     8     <body>    
     9         <button id="switch">Lady</button>
    10         <div id="content">        
    11         </div>                
    12     </body>
    13 </html>
    index.html
     1 require.config({
     2     baseUrl: 'js',
     3     paths:{
     4         'Lady': 'template/Lady.html',        
     5         'Sir': 'template/Sir.html'
     6     }
     7 });
     8 
     9 
    10 require(["jquery","domReady","text","text!Lady","text!Sir"],function($,domReady,text,Lady,Sir){                        
    11     domReady(function(){
    12         alert("Dom is ready!");
    13         $("#content").html(Lady);    
    14         $("#switch").click(function(){
    15             if($("#switch").text() == "Lady")
    16             {
    17                 $("#switch").text("Sir");
    18                 $("#content").html(Sir);
    19             }
    20             else
    21             {
    22                 $("#switch").text("Lady");
    23                 $("#content").html(Lady);
    24             }
    25         });
    26     });    
    27 });
    main.js
    1 <div>
    2     <br>Hello,Sir!<br>
    3 </div>
    Lady.html
    1 <div>
    2     <br>Hello,Lady!<br>
    3 </div>
    Sir.html

    Text : 在依赖前加前缀:text! ,文本文件就会自动加载。

    domReady:

      1)例子中API嵌套的方式应避免;

      2)以Loading Plugin语法加载,来强调在require回调函数之前,等待DOM Ready。Dom Ready会返回当前的doc。这种方式可能导致requirejs超时,可以考虑

    waitSeconds选项。

      eg:require(["domReady!"],function(doc){});

    学习记录,方便复习
  • 相关阅读:
    网络流模型之二分图匹配问题
    省选测试8
    省选测试9
    省选测试7
    省选测试6
    网络流最大流、最小割学习笔记
    kruskal重构树学习笔记
    省选测试5
    Python 打包成exe 方式
    JQuery
  • 原文地址:https://www.cnblogs.com/jingjingdidunhe/p/6535429.html
Copyright © 2020-2023  润新知