<script src="../js/seajs/dist/sea.js" type="text/javascript"></script> <script type="text/javascript" charset="utf-8" > //定义 define(function(require, exports) { return { msg:'hello world' } }); //调用 seajs.use('cons', function(cons) { alert(cons.msg); }); </script>
seajs与jquery结合,jquery可以直接调用不须要加definde:
<script src="../js/seajs/dist/sea.js" type="text/javascript"></script> <script type="text/javascript" charset="utf-8" > seajs.config({ // 设置别名,以方便调用 alias: { 'jquery': '/js/jquery-1.8b1.js' }, // 配置 shim 信息,这样我们就可以通过 require('jquery') 来获取 jQuery shim: { 'jquery': { exports: 'jQuery' } } }); //定义模块 define(function(require, exports, module){ //调用jquery require('jquery'); //模块内部对外提供接口 exports.say = function() { $("#form1").html("AAAA"); }; }); //调用 seajs.use('dom', function(dom) { dom.say(); }); </script> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body>