1-1 3s倒计时
<div id="app">
3
</div>
<script>
var num =3;
var app = document.getElementById("app");
// function go(){
// setTimeout(()=>{
// num--;
// if(num>=0){
// go();
// app.innerHTML = num;
// }
// },1000)
// }
// go();
var timer = setInterval(()=>{
num--;
console.log(num)
if(num>=0){
app.innerHTML = num;
}else{
clearInterval(timer)
}
},1000)
</script>
1-2按钮5s倒计时
<button id="btn">发送验证码</button>
<script>
var num =3;
var btn = document.getElementById("btn");
var timer;
btn.onclick = function(){
btn.disabled = true;
btn.innerHTML = num;
timer = setInterval(()=>{
num--;
if(num>=0){
btn.innerHTML = num;
}else{
btn.innerHTML = "发送验证码";
clearInterval(timer)
btn.disabled = false;
num=3;
}
},1000)
}
</script>
1-3 点击对应按钮,对应按钮删除
点击删除按钮,点击确定删除对应的元素
<ul>
<li>html <button>删除</button></li>
<li>css <button>删除</button></li>
<li>js <button>删除</button></li>
</ul>
var btns = document.getElementsByTagName("button")
for(var i=0;i<btns.length;i++){
btns[i].onclick = function(){
var temp = window.confirm("确定吗")
if(temp){
this.parentNode.style.display = "none"
}
}
}