zoukankan      html  css  js  c++  java
  • 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;
      }


  • 相关阅读:
    callable函数,检查对象是否可调用
    eval函数的一些用法
    divmod函数使用
    sorted(x, reverse=True)
    列表、元组、字典空格的几种移除方法
    约瑟夫环问题(通过观察得出递推式从而建立递归求解)
    快速幂算法(二分思想减少连乘次数)
    素数筛(埃氏筛法与欧拉筛)
    KMP算法的详细解释
    对于线性代数的形象化理解(1)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13314187.html
Copyright © 2011-2022 走看看