返回列表

Javascript无法输出tab的问题

默认分类 2011-10-27 02:39:14

目的:JS输出数据列表可以直接拷贝到Excel下

问题:JS无法直接输出制表符tab,所有tab在拷贝时均被替换成了空格

解决方法:输出<table>

Bug Demo:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled 1</title> <script type="text/javascript"> <!-- window.onload=function(){ document.body.innerHTML='123\t456'; } //--> </script> </head>

<body>

</body>

</html>

Fixed Demo:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled 1</title> <script type="text/javascript"> <!-- window.onload=function(){ document.body.innerHTML='<table><tr><td>123</td><td>456</td></tr></table>'; } //--> </script> </head>

<body>

</body>

</html>