0

大家好,我正在尝试在我的 html 中实现 jquery 代码,但它仅适用于 chrome、IE 和 firefox 不起作用,我没有足够的 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>
4

0 回答 0