有没有办法在客户端创建文本文件并提示用户下载它,而不与服务器进行任何交互?我知道我不能直接写入他们的机器(安全性和所有),但是我可以创建并提示他们保存它吗?
我正在尝试参考此代码,我们正在点击链接下载CSV文件.
$(document).ready(function () {
function exportTableToCSV($table, filename) {
var $rows = $table.find('tr:has(td)'),
// Temporary delimiter characters unlikely to be typed by keyboard
// This is to avoid accidentally splitting the actual contents
tmpColDelim = String.fromCharCode(11), // vertical tab character
tmpRowDelim = String.fromCharCode(0), // null character
// actual delimiter characters for CSV format
colDelim = '","',
rowDelim = '"\r\n"',
// Grab text from table into CSV formatted string
csv = '"' + $rows.map(function (i, row) {
var $row = …Run Code Online (Sandbox Code Playgroud)