首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法下载jquery文件下载

无法下载jquery文件下载
EN

Stack Overflow用户
提问于 2017-06-17 15:42:27
回答 1查看 451关注 0票数 0

我试图在我的代码中实现jquery filedownload,但它没有像预期的那样工作,我使用本地系统作为我的文件系统来下载文件,有人能在这方面帮助我吗?我是jquery的新手,或者更确切地说,提供了一个工作代码。

<%@ page language="java“contentType="text/html;字符集=ISO-8859-1”pageEncoding="ISO-8859-1"%>

代码语言:javascript
复制
$(document).on("click", "a.fileDownloadSimpleRichExperience", function () {
    $.fileDownload($(this).prop('href'), {
        preparingMessageHtml: "We are preparing your report, please wait...",
        failMessageHtml: "There was a problem generating your report, please try again."
    });
    return false; //this is critical to stop the click event which will trigger a normal file download!
});


</script>


<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<a href="E://Download/Anshuman.txt" class="fileDownloadSimpleRichExperience">Download</a>

</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2017-06-17 15:52:21

你试过这样做吗:

代码语言:javascript
复制
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<a href="E://Download/Anshuman.txt" class="fileDownloadSimpleRichExperience">Download</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).on("click", "a.fileDownloadSimpleRichExperience", function (e) {
  e.preventDefault();
 var hiddenElement = document.createElement('a');
hiddenElement.href = $(this).attr('href');
hiddenElement.download = 'aaa.csv';
hiddenElement.click();

});



</script>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44602060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档