首页 > 解决方案 > 单击按钮生成下载

问题描述

我正在制作一个具有 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>

标签: javascriptjqueryhtml

解决方案


推荐阅读