zoukankan      html  css  js  c++  java
  • requirejs-define jquery 快速初学实例(一)

    原文地址:http://6yang.net/articles_view.php?id=1103

    2011-10-18 13:12:01 by 【6yang】, 1029 visits, 收藏 | 返回

    实例说明:

    DEMO[require]: http://6yang.net/myjavascriptlib/requirejs/demo/d1.html

    DEMO[require-define]: http://6yang.net/myjavascriptlib/requirejs/demo/d2.html

    DEMO[require-config]: http://6yang.net/myjavascriptlib/requirejs/demo/d3.html

    说明下require,require-define,require-config,app-bulid.js(介绍)

    require: 主要任务包括异步载入事件及js库。

    define: 主要任务定义事件方便调用。

    require.config(): 主要任务配置相关参数。

    app-bulid.js: 建立app-build.js为是了nodejs创建项目使用的,分配目录。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>requirejs 应用</title>
    </head>
    <style>
    </style>
    <body>

    <!--<script src="js/jquery-1.6.2.min.js"></script>-->
    <script src="js/require.js"></script>
    <script>
    define("Employee", function () {
        //You can name this function here,
        //which can help in debuggers but
        //has no impact on the module name.
        return function Employee(first, last) {
            this.first = first; 
            this.last = last;
        };
    });

    /*
    define("main", ["Employee"], function (Employee) {
        var john = new Employee("John", "Smith");
        //alert(john.first);
    });*/

    /*  
     @ 这时的require包括了define里定义的对象变量及加载js文件对象.
     @ function(Employee)里的Employee,是需要通过define里的变量传递过来形参;
    */

    require(["Employee","js/test","http://code.jquery.com/jquery-1.6.4.min.js"], function(Employee) {
        var john = new Employee("John", "Smith");
         alert(john.first)
        alert(objstu.country);
        var inputVal = $("input:checkbox").prop("name");
        alert(inputVal);
    });


    </script>

    <div id="dic">sssssssssssss</div>
    用户名:<input type="text" name="username" value="1244555" /><br/>
    性别: <input type="checkbox" name="sex" value="0" /> 
    </body>
    </html>

    分享到:0
  • 相关阅读:
    可持久化BCJ
    Codeforces 911 三循环数覆盖问题 逆序对数结论题 栈操作模拟
    找不同
    最接近的三数之和
    找到所有数组中消失的数字
    三数之和
    小程序中的变量
    二叉树的最近公共祖先
    深拷贝和浅拷贝
    下载安装JDK
  • 原文地址:https://www.cnblogs.com/niaowo/p/4280294.html
Copyright © 2011-2022 走看看