<script>
let time ;
window.onload = function (){
time = setInterval("changeNumber()" , 1000);
}
function changeNumber(){
//修改 标题中的数字
//获得 数字的标签对象
let h = document.getElementsByTagName("h1")[0];
//let h = document.getElementById("v1");
console.log("我在运行中")
// 修改标签中的 数字 num--
let num = h.innerText;
//let num = h.valueOf();
num--;
if(num >= 0){
h.innerText = num;
}else{
//清空定时器
clearInterval(time);
}
}
</script>
</head>
<body>
<h1 id="v1">10</h1>
</body>
广告图片切换
<script>
let arr = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg"];
let img = document.getElementsByTagName("img")[0];
let index = 0;
fun();
function fun(){
img.setAttribute("src" , arr[++index % arr.length]);
setTimeout("fun()",1000);
}
</script>