下载<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>自动下载保单</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<style>
#ta {
width: 90%;
margin: 0 auto;
height: 350px
}
#second {
padding: 5px;
}
#btn {
background: #08f;
color: #fff;
outline: none;
border: none;
padding: 5px 10px;
cursor: pointer;
}
.disabled {
background: #999;
color: #333
}
.progress-bar {
/* 进度条的槽 */
width: inherit;
/* 设置进度条的高度 */
height: 5px;
/*进度条外层div的背景色,进度未达到的地方的颜色 */
background-color: #eee;
margin: 15px 0;
border-radius: 10px;
}
.progress {
/* 进度部分 */
/* 利用继承父元素宽度的百分比控制进度 */
width: 0;
height: 100%;
/* 内层背景色即进度达到的颜色 */
background-color: #25b668;
border-radius: 10px;
}
</style>
</head>
<body>
<div style="margin:auto;width:90%">
<h4 id="times"></h4>
<textarea id="ta">
</textarea>
<div class="progress-bar">
<div class="progress">
</div>
</div>
<div>
设置间隔<input type="number" step="10" id="second">秒
<button id="btn">自动批量下载</button> <span>下载进度:<b id='cur'>0</b>/<b id='total'>0</b>条</span> <span>还剩<b
id="rem"></b>条</span>
</div>
</div>
<script>
$(function () {
function getNowTime() {
//当前时间
var date = new Date();
//格式化时间
var localedata = date.toLocaleString();
//获取div标签
var divtime = document.getElementById("times");
//写入内容
divtime.innerHTML = localedata;
}
//利用定时器,动态刷新时间
setInterval(getNowTime, 1000);
// var url='http://www.epicc.com.cn/newecenter/serviceCenter/downLoadInfo.do?decPolicyNo='+bd+'&decIdentifyNo='+sfid+'&isCar=undefined';
var node = $('#ta').val('')
var initid;
var newnode;
var i = 0;
var begin = false;
$('#ta').keyup(function () {
var node = $('#ta').val()
node.replace(/(^\s+)|(\s+$)/g, "")
newnode = node.split(',')
console.log(newnode)
$('#total').text(newnode.length - 1)
})
$('#btn').click(function () {
if (begin == false) {
godown()
this.setAttribute("disabled", true)
}
else {
stopinitid()
}
})
function godown() {
let begin = true;
var second = $('#second').val()
initid = setInterval(gourl, second * 1000);
}
function gourl() {
if (newnode.length - 1 - i == 0) {
stopinitid()
} else {
console.log(newnode[i])
window.open(newnode[i], '_blank');
++i;
$('#cur').text(i)
$('#rem').text(newnode.length - i - 1)
var pro = (i / (newnode.length - 1)) * 100;
console.log(pro)
$('.progress').width(pro + '%')
}
console.log(i)
}
function stopinitid() {
clearInterval(initid);
}
})
</script>
</body>
</html>