<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>艾孜尔江的测试页</title>
</head>
<body>
<ul id="myid"></ul>
</body>
<script type="text/javascript">
let urls = [
"https://www.baidu.com",
"https://www.163.com",
"https://www.bing.com",
];
let openCount = 3;
function clickFunc() {
console.log("hello")
for (let i = 0; i < openCount; i++) {
document.getElementById("myLink" + i).click();
}
}
let str = '';
str += '<button id="mbtn" onclick="clickFunc">Open All</button>';
for (let i = 0; i < openCount; i++) {
let content = urls[i];
str += '<br>'
//str += '<li><div class="link">' + ("链接" + i) + '</div>';
//str += ' <div class="submenu">';
//str += ' <h3>' + ("Page" + i) + '</h3>';
////下方的target设为_blank之后一定要在浏览器的警告或拦截信息上点击“始终允许该站点打开多个点接...”;
////不然的话会出现只能打开一个页面的情况
str += ' <a id="myLink' + i + '"' + ' href="' + urls[i] + '" target=_blank>第' + i + '个</a > ';
//str += ' </div>';
//str += '</li>';
}
document.getElementById("myid").innerHTML = str;
let btn = document.getElementById('mbtn')
btn.onclick = clickFunc
</script>
</html>
艾孜尔江撰