<!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>Document</title>
<style>
div{
width: 600px;
margin: auto;
margin-top: 100px;
}
div a{
text-decoration: none;
font-size: 30px;
color: plum;
}
#sp_seconds{
color: red;
}
</style>
</head>
<body>
<div>
<a href="http://www.hao123.com">
<span id="sp_seconds">10</span> 秒钟后页面跳转,也可以单击跳转
</a>
</div>
<script>
function autoJump(sec,url){
let timer;
//1.获取span:可以动态改变数字
let span = document.getElementById('sp_seconds');
span.innerHTML = --sec
if(sec > 0){
// setTimeout('autoJump('+sec+',\''+url+'\')',1000)//其中\'的作用:取消URL中//的转义功能
timer = setInterval(`autoJump(${sec},\'${url}\')`,1000)
}else{
location.href = url
clearInterval(timer);
}
}
autoJump(10,'http://www.hao123.com')
</script>
</body>
</html>
<!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>Document</title>
</head>
<body>
<img src="./image/before.PNG" alt="" id="deng">
<script>
let flag = true;
let img = document.getElementById('deng');
img.addEventListener('click', function () {
if(flag){
img.src = './image/after.PNG';
flag = false;
}else{
img.src = './image/before.PNG';
flag = true;
}
})
</script>
</body>
</html>