大家好我正在尝试为我的html实现一个jquery代码,但它唯一的工作在chrome,IE和firefox doesen't工作,我还没有足够的javascript经验来找到这个请帮助。
我尝试在javascript上更改引号,但它也可以使用。
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js></script>
<script>
$(document).ready(function() {
$("#btnExport").click(function(e) {
//getting values of current time for generating the file name
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
//creating a temporary HTML link element (they support setting file names)
var a = document.createElement('a');
//getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById("dvData");
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//setting the file name
a.download = 'exported_table_' + postfix + '.xls';
//triggering the function
a.click();
//just in case, prevent default behaviour
e.preventDefault();
});
});
</script>
</head>
<body>
<div id="dvData">
<table border="0" cellspacing="2" cellpadding="10">
<tr>
<td>Tarih</td>
<td>ABD</td>
<td>Afganistan</td>
<td>Almanya</td>
</tr>
<tr>
<td>1993</td>
<td>100</td>
<td>200</td>
<td>300</td>
<tr>
<tr>
<td>1994</td>
<td>250</td>
<td>340</td>
<td>460</td>
</tr>
</table>
</div>
<button id="btnExport">Click for Save</button>
</body>
</html>