define(function(require, exports, modules) { // jquery 源码 return jQuery; });
seajs.config({ alias: { "jquery": "/js/jquery_cmd.js" // 这个路劲写对(本项目基于框架下面静态目录js下) } }); define(function(require, exports, module) { // 引入jquery模块 var $ = require(‘jquery‘); if (typeof $(‘h2‘) !== "undefined") { var oContent = { logText: ‘%c这是一个%c神奇的%c网站%c‘, cssStyle: [‘color:#a48bf2;‘, ‘color:#ff0000;‘, ‘color:#a0c484;‘, ‘padding:55px 135px;background:url(http://res.imtt.qq.com/actnew/css/head_logo.png) no-repeat center center;line-height:109px;‘] }; console.log(oContent[‘logText‘], oContent[‘cssStyle‘][0], oContent[‘cssStyle‘][1], oContent[‘cssStyle‘][2], oContent[‘cssStyle‘][3]); } else { console.log(‘not found‘); } });
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>seajs第一个应用</title> </head> <body> <h2>hello world</h2> <script src="/js/sea.js" id="seajsnode"></script> <script type="text/javascript"> seajs.use("/js/main"); </script> </body> </html>
define(function(require) { var $, jQuery; $ = jQuery = require(‘jquery‘); // 插件整个代码 });
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>requirejs引用echarts图表</title> </head> <body> <!-- 为Echarts准备一个具备大小(宽高)的Dom --> <div id="main" style="height:500px;border:1px solid #ccc;padding:10px;"></div> <script src="/js/require.js" id="requirejsnode"></script> <script type="text/javascript"> require.config({ paths: { // 这个路径写对(该项目基于WSP框架下静态目录js下) ‘echarts‘: ‘./js/echarts-map‘, ‘echarts/chart/bar‘: ‘./js/echarts-map‘, ‘echarts/chart/line‘: ‘./js/echarts-map‘, ‘echarts/chart/map‘: ‘./js/echarts-map‘ } }); require([ ‘echarts‘, ‘echarts/chart/bar‘, ‘echarts/chart/line‘, ‘echarts/chart/map‘ ], function(ec) { var domMain = document.getElementById(‘main‘); var myChart = ec.init(domMain); myChart.setOption({ tooltip: { trigger: ‘axis‘ }, legend: { data: [ ‘蒸发量‘, ‘降水量‘ ] }, toolbox: { show: true, feature: { mark: { show: true }, dataView: { show: true, readOnly: false }, magicType: { show: true, type: [ ‘line‘, ‘bar‘ ] }, restore: { show: true }, saveAsImage: { show: true } } }, calculable: true, xAxis: [ { type: ‘category‘, data: [ ‘1月‘, ‘2月‘, ‘3月‘ ] } ], yAxis: [ { type: ‘value‘, splitArea: { show: true } } ], series: [ { name: ‘蒸发量‘, type: ‘bar‘, data: [ 2.0, 4.9, 7.0 ] }, { name: ‘降水量‘, type: ‘bar‘, data: [ 2.6, 5.9, 9.0 ] } ] }); }); </script> </body> </html>
最后页面访问效果如图:
原文地址:http://blog.csdn.net/zqjflash/article/details/39676799