zoukankan      html  css  js  c++  java
  • js 下载文件

    window.open()只能打开一次,所以下载多个文件只能下载一个
    function download(name, href) {
    var a = document.createElement("a"), //创建a标签
    e = document.createEvent("MouseEvents"); //创建鼠标事件对象
    e.initEvent("click", false, false); //初始化事件对象
    a.href = href; //设置下载地址
    a.download = name; //设置下载文件名
    a.dispatchEvent(e); //给指定的元素,执行事件click事件
    }

    下载多个文件的思路的创建多个iframe,且不能马上删除
    var sites = ['url','url2']
    for (let i = 0; i < sites.length; i++) {
    const iframe = document.createElement("iframe");
    iframe.style.display = "none";
    iframe.style.height = 0;
    // url自己进行指定
    iframe.src = sites[i];
    document.body.appendChild(iframe);
    // 不能马上将iframe进行删除,否者也会出现马上取消的情况
    setTimeout(() => {
    iframe.remove();
    }, 3000);
    }
  • 相关阅读:
    (水题)洛谷
    (水题)洛谷
    洛谷
    (水题)洛谷
    POJ
    poj 3061(二分 or 尺取法)
    poj 2456(二分)
    poj 1064(二分答案)
    POJ 2559(单调栈)
    STL
  • 原文地址:https://www.cnblogs.com/shihx/p/12467246.html
Copyright © 2011-2022 走看看