• SeaJS入门篇一 怎么使用query


    研究了2个多小时,终于搞定引入jq

    1.写个html页面

    <h1>ddddddddd</h1>
    <script src='/Scripts/dist/sea.js'></script>

    2.配置脚本路径

    // seajs 的简单配置
            seajs.config({
                //base: "",//默认和sea.js同级,jquery.js和它同级,所以没有写;注意:如果为默认不要写,否则路径出错
                alias: {
                    "jquery": "jquery.js"
                }
            });

    但是,这样就query不能直接使用,需要修改jq文件

    define(function () {
    
      //juery原文件内容
      return $.noConflict();
    });

    好了,这样就解决了

    3.怎么定义模块

    这部门内容通常是写在js文件里,这里为了方便直接写在代码中

           // 所有模块都通过 define 来定义
            define("test", ["jquery"], function (require, exports, module) {
                // 通过 require 引入依赖
    
                var $ = require('jquery');
    
                // 通过 exports 对外提供接口
                exports.doSomething = function () { 
                    alert(1);
                    return 1;
                }
    
                function Test(h1) {
                    this.h1 = $(h1);
                }
    
                // 或者通过 module.exports 提供整个接口
                module.exports = Test;
    
                Test.prototype.change = function () {
                    var h1 = this.h1;
                    $(h1).css("color", "red");
                }
            });
            define("main", ["test", "jquery"], function (require, exports, module) {
                var t = require('test');
                var tt = new t("h1");
                tt.change();
            });

    4.加载入口

            // 加载入口模块
            seajs.use("main");

    最终效果显示:

    ddddddddd

  • 相关阅读:
    PAT (Basic Level) Practise:1001. 害死人不偿命的(3n+1)猜想
    流加密法
    The NMEA 0183 Protocol
    USB 描述符
    网摘
    What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?
    Why did Jimmy Wales invest in Quora? Is he afraid that it will take over Wikipedia?
    Add Binary
    Cocos2d-x 网络资源
    Cache
  • 原文地址:https://www.cnblogs.com/xcsn/p/5698357.html
Copyright © 2020-2023  润新知