N 秒打开一个新窗口
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
</head>
<body>
<a id="article"
target="_blank"><span id="spanId">点击</span>d</a>
<script>
$("#article").click(function() {
openNewWindow();
setTimer();
});
var n = 0;
function setTimer() {
n++;
$("#article").text("已点击" + n + "次");
setTimeout(function() {
openNewWindow();
setTimer();
}, 2000)
}
function openNewWindow() {
//var a = $('a')[0];
let a = $("<a href='http://baijiahao.baidu.com/s?id=1588483985812614469&hidebar=1' target='_blank'>baidu</a>").get(0);
let e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
}
</script>
</body>
</html>
本文来自博客园,作者:每天都要学一点,欢迎讨论和转载,转载请注明原文链接:https://www.cnblogs.com/yanan7890/p/8604264.html