首页 > Web开发 > 详细

seajs使用demo

时间:2015-02-09 15:42:05      阅读:367      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/hanbingljw/p/4281439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!