zoukankan      html  css  js  c++  java
  • seajs使用demo

    初试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

  • 相关阅读:
    Android 开发转型前端准备知识
    atom写文档技巧
    gerrit升级到16.04之后连接不到服务器
    adb shell am pm
    ArrayList和LinkedList的区别
    Android源码编译
    Android动态加载代码技术
    File 与 FileStream 文件运用
    物体在一定范围自有碰撞
    扫描二维码加载网页图片
  • 原文地址:https://www.cnblogs.com/hanbingljw/p/4281439.html
Copyright © 2011-2022 走看看