JavaScript模組載入架構sea.js 學習一,javascriptsea.js

來源:互聯網
上載者:User

JavaScript模組載入架構sea.js 學習一,javascriptsea.js

簡單總結sea.js 學習

檔案目錄結構

  /sea/sea.js        http://seajs.org/docs/#downloads

  /sea/jquery-sea.js    http://jquery.com/download/

  /sea/sea_config.js

  /sea/home.jsdata.js

  /sea/data.js


1.html頁面代碼檔案

<style> .ch{height:200px;width:200px;background:#ccc;}</style><div class="cl"></div><!-- 引入sea.js檔案 --><script src="/sea/sea.js"></script><!-- 引入sea_config.js設定檔 --><script src="/sea/sea_config.js"></script>   <script type="text/javascript"> seajs.use(['jquery','home'],function(a,b){    //alert(b.foo);  //調用home中的foo屬性    b.init();      //調用home中的init介面b.all();       //調用home中的all介面 }) </script>

2.sea_config.js設定檔

seajs.config({  // 別名配置  alias: {    'jquery': '/sea/jquery-sea',    'home': '/sea/home','data': '/sea/data'  },  // 路徑配置  //paths: {  //  'gallery': 'https://a.alipayobjects.com/gallery'  //},  // 變數配置  //vars: {  //  'locale': 'zh-cn'  //},  // 映射配置  //map: [  //  ['http://example.com/js/app/', 'http://localhost/js/app/']  //],  // 預先載入項 //preload: ['jquery','home'],  // 偵錯模式  debug: true,  // Sea.js 的基礎路徑  //base: 'http://example.com/path/to/base/',  // 檔案編碼  charset: 'utf-8'});

3.home.js模組檔案

define(function(require, exports, module){ var data = require('data');  // 載入data模組 data.js function wo(){       //內建函式,init中調用   alert("load $"); };   alert(data.blog);   //直接執行函數 module.exports = {             //當前模組對外提供的介面    foo:'hello',  //屬性          init : function(){      //介面initwo();    //執行內建函式        $(".cl").addClass("ch");        },    all : function(){       //介面all  alert(data.author);}        };console.log(require.resolve('jquery'));  //require.resolve返回別名檔案 解析後的絕對路徑});

4.data.js模組檔案

define({    author: 'ZhangYanpo',    blog: 'http://www.ktuo.cn'});



JavaScript推薦一個好的對於JavaScript的網站,學習之用,

1. www.w3school.com.cn/javascript/ 基礎學習

2.右擊任何一個網站,查看原始碼,然後再查看一下他們的 js 的原理,學習一下
從 三流網站,排名低的 => 中型網站 => 門戶網站

3. jq 核心,學完後,JS 沒有難度了,只怕想不出.( 上次幫別人做了一個立體3D球形,並帶陰影製作效果的.全部用代碼產生出來.還做過JS的mmorpg遊戲,ajax+flash socket,但總感覺有點慢............)
 
javascript要讓頁面載入時執行一個函數應該怎做?

<script type="text/javascript">
function finish(){

alert('hello');
}
</script>
<body onload="finish()">
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.