如何在数据表引导程序中点击Excelbutton来增加javascriptvariables

var counter = 0; function staticVar() { if (staticVar.counter == undefined) { staticVar.counter = 1 } else { staticVar.counter++ } return staticVar.counter; } //Our table has horizontal and vertical scroll bars and the first columni.e, the serial number will be fixed when scrolling $(document).ready(function() { var download_file_counter= staticVar(); var table = $('#example').DataTable({ "aoColumnDefs": [{ "bSortable": false, "aTargets": [0] }], scrollY: '40vh', scrollX: '40vh', paging: true, pageLength: 20, lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]], dom: 'Bflrtip', buttons: [{ extend: 'print', exportOptions: { columns: ':visible' } }, { extend: 'colvis', className: 'colvisButton' }, { extend: 'excelHtml5', title: 'LicenseDetails_'+(++download_file_counter)+'_'+today, text: 'Excel', exportOptions: { modifier: { page: 'current' } } }], columnDefs: [{ targets: -1, visible: false, orderable: false }], order: [[ 1, 'asc' ]] }); download_file_counter= makeCounter(); $('#start-date, #end-date').change(function () { table.draw(); }); $('#start-date1, #end-date1').change(function () { table.draw(); }); $('#start-date2, #end-date2').change(function () { table.draw(); }); }); 

这是我的JavaScript代码,我想通过点击Excelbutton将计数器variables传递给文件名。 这个计数器不是递增的。