我正在尝试将其从单击功能转换为Onload



我有一个从HTML表数据生成CSV文件的脚本。单击链接类导出时,下面的脚本强制下载。我希望在页面加载时自动发生这种情况。这是可能的吗?

$(".export").on('click', function (event) {
    // CSV
    var args = [$('#output>table'), 'heartbeat.csv'];
    exportTableToCSV.apply(this, args);
    // If CSV, don't do event.preventDefault() or return false
    // We actually need this to be a typical hyperlink
});

带有jQuery,有一个.ready()侦听器函数,您可以这样设置:

$(document).ready(function(){
    var args = [$('#output>table'), 'heartbeat.csv'];    
    exportTableToCSV.apply(this, args);
});

我强烈建议您在此处查看文档:https://learn.jquery.com/ususe-jquery-core/document-ready/

最新更新