使用java中的jquery以zip格式下载多个文件

时间:2015-10-27 12:17:51

标签: jquery jsp

我有这种情况,其中jsp包含三个复选框,这些复选框是链接。如果我检查任何方框并单击提交按钮,我必须下载一个包含链接所有内容的zip文件夹。如果由JQuery完成它会更好。

这是我到目前为止所做的代码:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script type="text/javascript">
  function downloadFunction(checkboxName) {
        var checkboxes = document.querySelectorAll('input[name="' + checkboxName + '"]:checked'), values = [];
        Array.prototype.forEach.call(checkboxes, function(el) {
            values.push(el.value);
        });
        var link = document.createElement('a');
        link.setAttribute('download', null);
        link.style.display = 'none';
        document.body.appendChild(link);

        for (var i = 0; i < values.length; i++) {
          link.setAttribute('href', values[i]);
          link.click(); 
        }

        document.body.removeChild(link);
    }
  </script>

</head>
<body>
    <form action="">
        <input type="checkbox" name="link" checked="checked" value="https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.exe">file1
        <input type="checkbox" name="link" value="https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.dmg">file2
        <input type="checkbox" name="link" value="https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar">file3<br>
        <input type="submit" name="submit" value="Submit" onclick="downloadFunction('link');">
    </form>
</body>
</html>

我无法继续前进。

0 个答案:

没有答案