从导入的文件中使用Javascript函数

从导入的文件中使用Javascript函数,javascript,Javascript,我有一个文件,在标签中声明了函数sendTableToExport,我在这个文件中包含了另一个文件,我需要在其中调用这个函数。这可能吗?因为只有当我将调用脚本移到主文件中时,它才对我有效。但它必须包含在文件中。然后记录引用错误:未定义sendTableToExport 主文件中的脚本: function sendTableToExport(tableSelector, fileName, format) { // function body } 和包含在文件中的脚本:

我有一个文件,在
标签中声明了函数
sendTableToExport
,我在这个文件中包含了另一个文件,我需要在其中调用这个函数。这可能吗?因为只有当我将调用脚本移到主文件中时,它才对我有效。但它必须包含在文件中。然后记录引用错误:未定义sendTableToExport

主文件中的脚本:

function sendTableToExport(tableSelector, fileName, format) {
    // function body
}
和包含在文件中的脚本:

        $(document).on ("click", ".export-tz-ku-lv", function () {
            sendTableToExport(".tz-ku-table-view-lv tr", 'Dashboard - Prehled TZ dle KU - pocty LV', $(this).data('format'));
        });
        $(document).on ("click", ".export-tz-ku-land", function () {
            sendTableToExport(".tz-ku-table-view-land tr", 'Dashboard - Prehled TZ dle KU - pocty parcel', $(this).data('format'));
        });
        $(document).on ("click", ".export-tz-ku-proportion", function () {
            sendTableToExport(".tz-ku-table-view-proportion tr", 'Dashboard - Prehled TZ dle KU - pocty vlastnickych podilu', $(this).data('format'));
        });

我找到了解决办法。我只需要编辑声明以

window.sendTableToExport = function ()....

理论上应该没问题。请说明如何以及在何处将文件包含到主文件中。您是在声明
sendTableToExport
函数之前还是之后包含它?@ADyson它是在函数声明之前包含的,请在声明之后包含它。