0

此示例在 jsFiddle 中运行良好,但将表格导出到 Excel 工作表中

我保存在PC中,如下面的代码

<html>
<head>
  <title>Table Export</title>
  <script src="jquery.js"></script>

  <script type="text/javascript">
$("#btnExport").click(function (e) {
    window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#dvData').html()));
    e.preventDefault();
});
</script>
</head>

<body>
  <br/>
<div id="dvData">
<table>
    <tr>
        <th>Column One </th>
        <th>Column Two</th>
        <th>Column Three</th>
    </tr>
    <tr>
        <td>row1 Col1</td>
        <td>row1 Col2</td>
        <td>row1 Col3</td>
   </tr>
   <tr>
        <td>row2 Col1</td>
        <td>row2 Col2</td>
        <td>row2 Col3</td>
   </tr>
      <tr>
        <td>row3 Col1</td>
        <td>row3 Col2</td>
        <td>row3 Col3</td>  
   </tr>
</table>
</div>
<br/>
<a href="" id="btnExport">edit</a>
</body>
</html>

但这不起作用并导出文件,但其他 jQuery 示例有效,有什么问题?

4

1 回答 1

2

像这样使用准备好的文档

  <script type="text/javascript">
  $(document).ready(function(){
  $("#btnExport").click(function (e) {
     window.open('data:application/vnd.ms-excel,' +encodeURIComponent($('#dvData').html()));
    e.preventDefault();
  });
  });
  </script>
于 2013-01-26T09:30:37.787 回答