js文件的互调

来源:互联网 发布:万方数据库免费下载 编辑:程序博客网 时间:2024/06/05 11:33

本文将举例,说明js文件的互调问题

1.创建main.html文件,用于关联js文件

<!DOCTYPE html>
<html>
<head>
    <title>函数作用域测试</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="js/abc.js"></script>
    <script src="jscore/datahandler.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            alert("123");
            ABC.autoDownload();
        });
    </script>
</head>
<body>
    <p>1.在head标签中,添加script标签,引入相应的js文件</p>
    <p>2.调用js文件夹中的ABC.autoDownload()函数</p>
    <p>3.调用jscore文件夹中的DATAHANDLER.upload.init()函数</p>
</body>
</html>

2.创建js文件夹,在此文件夹中新建一个abc.js文件

/**
 * Created with JetBrains WebStorm.
 * User: ABCUSER
 * Date: 13-7-31
 * Time: 下午6:38
 * To change this template use File | Settings | File Templates.
 */
var ABC={
    autoDownload:function(){
        alert("in autoDownloas()");
        DATAHANDLER.upload.init();
    }
};


3.创建jscore文件夹,在此文件夹中创建datahandler.js文件

/**
 * Created with JetBrains WebStorm.
 * User: ABCUSER
 * Date: 13-7-31
 * Time: 下午6:44
 * To change this template use File | Settings | File Templates.
 */
var DATAHANDLER={};
DATAHANDLER.upload= {
    init:function(){
        alert("in DATAHANDLER.upload");
    }
}

当然,名字都是可以自己随意命名的。