5 Star 19 Fork 2

陈轩大魔王 / Excel_JS_Runtime

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
how_To_Import_Js_File.md 1.79 KB
一键复制 编辑 原始数据 按行查看 历史

引入JS文件


引入JS文件的基础方法

通过 define 函数定义模块,在 define 函数的第一个参数中以数组形式传入要引入的js文件路径。

注: 下称 define 函数的第一个参数为: 引入JS文件的数组,即 JS_FP

下面是目前所支持的 define 用法,和AMD规范有所不同,目前尚未实现所有AMD规范。

define([],function (){});

如要引入 t2.js,应该如下写

define(
    ["t2.js"],
    function (t2)
    {
        return "t1";
    }
)

当然 t2.js 必须通过 define 函数进行定义

t2.js 如下

    define(
        [],
        function ()
        {
            return "I am t2";
        }
    )

若要引入多个js文件,应该如下写:

define(
    [
        "t2.js",
        "t3.js",
        "t4.js"
    ],
    function (t2, ttt, tttt)
    {
        return "t1";
    }
)

当 JS文件 在 base.xlsm 中的 BASE_CODE_LIB 时

JS_FP 中添加js在BASE_CODE_LIB中的A列内容即可

如 a.js 在BASE_CODE_LIB的A列为 /test/a.js ,则如下:

    define(
        ["/test/a.js"],
        function (a)
        {
            return "t1";
        }
    )

当 JS文件 作为.js文件在 base.xlsm 外时

JS_FP 中添加该js位于 base.xlsm 的相对路径

若目录结构如下

workplace
│  base.xlsm

└─tXXX
        t2.js

代码如下:

    define(
        ["file://tXXX/t2.js"],
        function (a)
        {
            return "t1";
        }
    )

当 JS文件 在服务器上时

JS_FP 中添加该js的URL即可

    define(
        [
            "http://www.tt.com/t2.js",
            "https://www.tt.com/t3.js"
        ],
        function (a, t3)
        {
            return "t1";
        }
    )
JavaScript
1
https://gitee.com/cxwithyxy/Excel_JS_Runtime.git
git@gitee.com:cxwithyxy/Excel_JS_Runtime.git
cxwithyxy
Excel_JS_Runtime
Excel_JS_Runtime
master

搜索帮助