uncaught exception: INVALID_CHARACTER_ERR: DOM Exception 5

1、错误描述

uncaught exception: INVALID_CHARACTER_ERR: DOM Exception 5

2、错误原因

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>导出Excel格式</title>
		<script type="text/javascript" src="js/jquery-1.12.3.js" ></script>
		<script type="text/javascript" src="js/jquery.base64.js" ></script>
		<script type="text/javascript" src="js/tableExport.js" ></script>
		<script type="text/javascript" src="js/jspdf/libs/sprintf.js" ></script>
		<script type="text/javascript" src="js/jspdf/jspdf.js" ></script>
		<script type="text/javascript" src="js/jspdf/libs/base64.js" ></script>
		<script>
			$(document).ready(function(){
				$("#exportData").click(function(){
					$("#tables").tableExport({type:"excel",escape:"false"});
				});
			});
		</script>
	</head>
	<body>
		<table id="tables">
			<thead>
				<tr>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>住址</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市洪山区</td>
				</tr>
				<tr>
					<td>丽丝</td>
					<td>女</td>
					<td>24</td>
					<td>湖北省黄冈市</td>
				</tr>
				<tr>
					<td>李华</td>
					<td>女</td>
					<td>25</td>
					<td>湖北省黄石市</td>
				</tr>
			</tbody>
		</table>
		<input type="button" id="exportData" value="导出"/>
	</body>
</html>

     这里是一个外国人写的导出的JS,没有考虑到中文情况

function _getbyte( s, i ) {
    var x = s.charCodeAt( i );

    if ( x > 255 ) {
      throw "INVALID_CHARACTER_ERR: DOM Exception 5";
    }
    
    return x;
  }


3、解决办法

      将上述JS中的if判断修改下:

  function _getbyte( s, i ) {
    var x = s.charCodeAt( i );

    if ( x > 65536 ) {
      throw "INVALID_CHARACTER_ERR: DOM Exception 5";
    }
    
    return x;
  }


你可能感兴趣的:(jquery,导出)