seajs实例
点击文本改变:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>seajs demo</title> <script src="js/jquery-1.3.2.min.js"></script> </head> <body> <div id="box">这是box</div> <script> $(document).ready(function(){ $("#box").click(function(){ $(this).text("change ok"); }) }) </script> </body> </html>
利用seajs完成以上效果:
demo.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>seajs demo</title> </head> <body> <div id="box">这是box</div> <script src="js/sea.js" ></script> <script> // seajs 的简单配置 seajs.config({ base: "./js/", alias:{ "jquery":"jquery-1.3.2.min.js" } }) seajs.use("main"); </script> </body> </html>
main.js
// 所有模块都通过 define 来定义 define(function(require, exports, module) { require('jquery'); //普通jquery库 var demo=require('demo'); demo.doSomething(); });
demo.js
define(function(require, exports, module) { var a={}; a.doSomething=function(){ $("#box").click(function(){ $(this).text("change ok"); }); } module.exports=a; });
2024还活着,挺好的,向着星辰与深渊,加油,博客园不要倒下啊!