js文件之间调用函数

2018-06-04  本文已影响0人  从前慢pearl

1,index.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>

<script src="jquery.min.js"></script>    //引入jquery文件
<script src="api.js"></script>          //api公用函数文件
<script src="index.js"></script>      //调用api文件函数的文件
</body>
</html>

2,api.js文件

方案一:

    (function ($, owner) {
        owner.console = function(n){
            console.log("调用console函数输出值")
            console.log(n)
        }
    }(jQuery, Api = {}));

方案二:

    var Api = {
        console : function(n){
            console.log("调用console函数输出值")
            console.log(n)
            console.log("看看jquery能不能调用")
            console.dir($)
        }
    }

3,index.js文件调用api文件里面的函数

Api.console("这是inde.js文件")
上一篇下一篇

猜你喜欢

热点阅读