seajs使用demo

來源:互聯網
上載者:User

標籤:

初試seajs,為下次項目的實戰做準備:

html:

seajsDemo.html

<!DOCTYPE html><html><head><meta charset="utf-8"><title>seajsdemo</title><script src="../js/seajs2.2.0/sea.js"></script><script src="../js/seajs2.2.0/sea-debug.js"></script></head><body><div class="wrap"><span>使用seajs載入js</span><div class="content">內容</div></div></body><script>var app = {};app.debug = false;window.app.controller = "demo1";seajs.config({base:"../js/seaDemo",alias:{"jQuery":"jquery.js"},paths:{"jQuery":"jquery.js"}});seajs.use("../js/seaDemo/app.js");</script><!--seajs入口--></html>

 js:

app.js

/***seajs入口*調用其他程式*/define(["jQuery"],function(require,exports,module){  //  window.$ = window.jQuery = require("jQuery"); exports.load = function(name){     require.async("../seaDemo/"+name+".js",function(controller){if(typeof(controller.run) =="function"){controller.run(); //運行需要載入的js}})}/******/window.app.load = exports.load;if(window.app.controller){exports.load(window.app.controller);}/***調用載入**/});

 demo1.js

define(function(require,exports,module){exports.run = function(){alert("已調用demo1.js"); $(".content").text("hello seajs");}});

 目錄結構:

html位置:demo/html/seajsDemo.html

 

seajs使用demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.