Php 使用javascript(Jquery)从html表导出csv

Php 使用javascript(Jquery)从html表导出csv,php,Php,我尝试使用jquery将json-to-html表导出到csv。但导出后,当我打开文件时,它的工作正常。 但是,它不适用于Internet Explorer(IE)的任何版本 $(document).ready(function () { function exportTableToCSV($table, filename) { var $rows = $table.find('tr:has(td,th)'), tmpColDelim = S

我尝试使用jquery将json-to-html表导出到csv。但导出后,当我打开文件时,它的工作正常。 但是,它不适用于Internet Explorer(IE)的任何版本

$(document).ready(function () {

    function exportTableToCSV($table, filename) {

        var $rows = $table.find('tr:has(td,th)'),

            tmpColDelim = String.fromCharCode(11), 
            tmpRowDelim = String.fromCharCode(0),

            colDelim = '","',
            rowDelim = '"\r\n"',

            csv = '"' + $rows.map(function (i, row) {
                var $row = $(row),
                    $cols = $row.find('td,th');

                return $cols.map(function (j, col) {
                    var $col = $(col),
                        text = $col.text();

                    return text.replace('"', '""'); 

                }).get().join(tmpColDelim);

            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',

            csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);

        $(this)
        .attr({
            'download': filename,
            'href': csvData,
            'target': '_blank'
        });
    }

    $(".export").on('click', function (event) {
        // 
        var d = new Date();
        var filename = d.toDateString();
        exportTableToCSV.apply(this, [$('#dvData>table'), filename+'.csv']);
    });
});