使用java脚本导出html表格excel 当它find'#'字符时不导出

我需要一个JavaScript将HTML表格导出到Excel。 我已经试过这个脚本,这是出口,但是当它发现特殊字符,即'#'它停在那里它自我不导出进一步的行。

任何人都可以帮助我,提前谢谢

<script src="/tpComment.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> \$(function() { \$("#btnExport").click(function(e) { var data_type = 'data:application/vnd.ms-excel'; var table_div = document.getElementById('dvData'); var table_html = table_div.outerHTML.replace(/ /g, '%20'); window.open(data_type + ', ' + table_html); e.preventDefault(); //getting values of current time for generating the file name }); }); </script> <input type="button" onclick="CreateExcelSheet()" value="Create Excel Sheet"> <div id="dvData" > <table > <tr> <th>name</th> <th> address </th> <th> no </th> </tr><tr> <td>ABC</td> <td>#17 </td> <td>99999</td> </tr></table></div> 

感谢您的build议。 我正在使用URL编码。下面的脚本工作正常的特殊字符。 我的解决scheme可能有助于他人。

  <script src="/tpComment.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(function() { $("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#dvData').html())); e.preventDefault(); }); });