0
我有一个文件,里面的<script></script>
标签声明功能sendTableToExport
和我包括另一个文件到这个,我需要调用这个函数。这甚至有可能吗?因为只有当我将该调用脚本移动到主文件时它才适用于我。但它必须在包含文件中。而比它记录ReferenceError: sendTableToExport is not defined
使用从导入的文件中的Javascript功能
脚本在主文件:
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'));
});
它理论上应该是好的。请说明你如何和_where_将文件包含在主文件中。你是否在声明'sendTableToExport'函数之前加入它,或者之后呢? – ADyson
@ADyson在函数被宣布为 – HS1993
之前包含在它之后。 – ADyson