javascript - 单击按钮生成下载
问题描述
我正在制作一个具有 csv 表单的网页。当我单击按钮并且窗口提示正确时,我想下载 csv 文件。
EX:我点击下载按钮,会弹出一个窗口提示我需要输入“你好”才能认证正确,如何在输入正确时下载csv表格,错误时不下载。谢谢
这是我的来源:
代码
<a href="#" class="download" onclick="myFunction()">Download</a>
<script type="text/javascript">
$('.download').click(function(e) {
var person = prompt("Please enter download access", "Hello Admin");
e.preventDefault(); //stop the browser from following
if (person != "Hello") {
$('#auth__text').show();
$('#auth__text__success').hide();
document.getElementById("auth__text").innerHTML = "Wrong Access, You can't Download the CSV Data(s)";
} else {
$('#auth__text').hide();
$('#auth__text__success').show();
document.getElementById("auth__text__success").innerHTML = "You can now download the CSV Data(s)";
}
});
</script>
解决方案
推荐阅读
- azure - Azure 管道任务 DotNetCoreCLI@2 - 工件的输出文件夹
- openldap - 我无法从 openLDAP 数据库中检索所有条目
- javascript - API 不接收通过 FormData 发布的文件 + 文本
- excel - Excel VBA:单列:在下面查找文本,复制文本和其他行的文本,在第二个选项卡上转置为列
- database - 是否可以通过delphi中的组合框清除列表框
- azure - VPN 到 Azure 网关连接但不解析地址
- python - 对 Pandas 列中的一串数字进行排序
- asp.net - 如何在 Blazor Web Assembly 应用程序中返回 403 Forbidden 而不是重定向?
- reactjs - 这段代码中的 useEffect 依赖项应该添加什么?
- reactjs - React-pdf 框架比例