js导出CSV

其实就是a标签的下载功能,通过js来触发a标签click时间则可以实现延时下载等等

<html>
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"> 
<meta name="author" content="oscar999"> 
<title> 
</title> 
<script> 
function clickDownload(aLink) 
{ 
var str = "栏位1,栏位2,栏位3
值1,值2,值3,10"; 
str = encodeURIComponent(str); 
aLink.href = "data:text/csv;charset=utf-8,ufeff"+str; 
} 
</script> 
</head> 
<body> 
<a id="test" onclick="clickDownload(this)" download="下载.csv" href="#">download</a> 
</body> 
</html>
原文地址:https://www.cnblogs.com/ericwangz/p/6873011.html