1, first import the corresponding JS file
<script src= "Js/require.js" ></script> <script src= "Js/mian.js" ></script> < Script src= "Js/index.js" ></script>
Require.js is Requirejs library, Mian.js is used to write require configuration information, and index is to write their own logic code
2. Write Mian.js configuration information
require.config ({ baseUrl:' js/',// definition with path paths:{ ' jquery ': ' jquery ', ' bootstrap ': ' Bootstrap.min ', ' utils ': ' Utils ' }, dependency, load boostrap before loading jquery shim:{' Bootstrap ': { ' deps ': [' jquery ']}}} );
3. Then implement your own code in your Index.js file
// Simple introduction of jquery library function ($) { $ ("Body"). css ({ "background-color": "Red" }) ;
Introducing JS libraries through dependency relationships
// dependencies in Mian.js, load boostrap before loading jquery shim:{ ' Bootstrap ': { ' deps ': [' jquery '] } }// the jquery library function () is then introduced in its own index.js// dependencies when introducing the Boostrap library () { $ ("Body"). css ({ "background-color": "Red" }) ;
4. Define your own Utils.js library
define ([' jquery '],function($) { return {change :function () { $ ("Body"). css ({ "background-color": "Red" }); }, show: function () { alert ("show");}} );
In your own JS file
Customize your own library, and then introduce
Require ([' utils '], function (utils) {
Utils.show ();
Utils.change ();
});
Resources: http://download.csdn.net/detail/u013865056/9915553
Requirejs Simple Application