我的写法,可以看下给点意见
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button id="but">获取数据</button>
<ul class="list">
</ul>
<h1>操作成功</h1>
<p><span class="ys" id="ys">5</span>秒后回到主页</p><a id="btn">返回</a>
</body>
<script src="./js/jquery.min.js"></script>
<script>
var num = 5;
var interval;
function aa(){
num --;
if(num == 0){
// alert('ss');
clearInterval(interval)
window.location.href = "http://www.baidu.com";
}else{
document.getElementById("btn").onclick = function(){
window.history.forward();
// alert('dd')
}
}
console.log(num);
//JQ写法
// $(".ys").html(num);
// JS写法
document.getElementById("ys").innerHTML=num;
}
interval = setInterval(aa,1000);
</script>
</html>