JQuery当表具有ID或类时,将表导出为Excel错误
如果<table>
没有ID或类,我可以使用jquery导出HTML表格:
http://jsfiddle.net/n9XRx/
但是,如果我的表有一个ID或一个类attr下面的jquery踢出一个单元格中的一个HTMLstring,以Excel:
$( "#clickExcel" ).click(function() { var dtltbl = $('#dtltbl').html(); window.open('data:application/vnd.ms-excel,' + $('#dtltbl').html()); });
我可以通过删除表类和ID来解决这个问题,但这并不理想。 任何人都有解决scheme?
打开之前,您可以对string进行编码。
$( "#clickExcel" ).click(function() { var dtltbl = $('#dtltbl').html(); window.open('data:application/vnd.ms-excel,' + encodeURI($('#dtltbl').html())); });
我和你有同样的问题,并已经这样解决:
$("#btnExport").click(function (e) { window.open('data:application/vnd.ms-excel,' +'<table>' +$("#YourTableId").html()+ '</table>'); e.preventDefault(); });
希望能帮助到你