打赏

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>

posted @ 2018-03-19 19:45  每天都要学一点  阅读(181)  评论(0编辑  收藏  举报