使用jquery下载文件自定义名称 [英] Downloading file custom name with jquery
本文介绍了使用jquery下载文件自定义名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery 插件将HTML表格导出到Excel。使用chrome下载的文件名始终为 download.xls
,并使用mozilla firefox,它是 random-string.xls
。我希望根据日期创建文件名。例如 23-06-2014.xls
。
I am using a jQuery plugin to export HTML table to Excel. The downloaded file name using chrome is always download.xls
and using mozilla firefox it is random-string.xls
. I want file name to be created according to date. For example 23-06-2014.xls
.
以下是视图文件中的自定义JS块
Below is the custom JS block in view file
$(document).ready(function () {
$("#btnExport").click(function () {
$("#account_table").btechco_excelexport({
containerid: "account_table",
datatype: $datatype.Table
});
});
});
推荐答案
你想设置在链接上下载
和 href
属性。例如
$("#btnExport").click(function () {
var uri = $("#account_table").btechco_excelexport({
containerid: "account_table",
datatype: $datatype.Table,
returnUri: true
});
$(this).attr('download', 'ExportToExcel.xls') // set file name (you want to put formatted date here)
.attr('href', uri) // data to download
.attr('target', '_blank') // open in new window (optional)
;
});
这篇关于使用jquery下载文件自定义名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文