html调用commonjs规范的js
作者:互联网
a.js
define(function(require, exports, module) { var test = function(){ console.log("hello world") } //if using just this, Tern doesn't get it, but works with RequireJS module.exports = test; //this works with Tern already // return test; });
test.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <button onclick="test()">test</button> <script> function test() { require(['./a.js'], function (sayHi) { console.log(sayHi); }); } </script> <script src="https://requirejs.org/docs/release/2.3.6/minified/require.js"></script> </body> </html>
标签:function,commonjs,console,log,js,html,test,sayHi 来源: https://www.cnblogs.com/kunyashaw/p/10896047.html