脚本宝典收集整理的这篇文章主要介绍了seajs 的第一个demo,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
seajs 主要解决了俩个问题:命名冲突、文件依赖关系
第一步:把引用的库用require 包装起来,比如jquery库 (jquery_cmd.js)
define(function(require, exports, modules) {
// jquery 的代码
return jQuery;
});
第二步:写引人的js (demo.js)
seajs.config({
alias: {
"jquery": "../scripts/jquery/jquery_cmd.js" // 这个路劲写对
}
});
define(function(require, exports, module) {
VAR $ = require('jquery');
console.LOG($('body'));
});
第三步:HTML
@H_360_98@<!DOCTYPE htML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<script src="scripts/seajs/sea.js" id="seajsnode"></script>
<script type="text/javascript">
seajs.use("./static/demo");
</script>
</body>
</html>
大工告成!
以上是脚本宝典为你收集整理的seajs 的第一个demo全部内容,希望文章能够帮你解决seajs 的第一个demo所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。