此代码会在5秒后自动跳转其他界面,点击按钮后直接跳转
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button>点击</button>
<div></div>
<script>
var btn = document.querySelector('button');
var div = document.querySelector('div');
btn.addEventListener('click', function() {
// console.log(location.href);
location.href = 'http://www.itcast.cn';
})
var timer = 5;
setInterval(function() {
if (timer == 0) {
location.href = ' 输入需要跳转的网址链接,请勿删除引号 ';
} else {
div.innerHTML = '您将在' + timer + '秒钟之后跳转';
timer--;
}
}, 1000);
</script>
</body>
</html>
©造梦空间论坛
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容