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;
  }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值