<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="btn">点击获取文字</button>
<!--
1.什么函数才是回调函数?
* 自定义
* 没有调用,但是执行了
2.常见的回调函数?
* dom事件回调函数 ——> this是 发生事件的dom元素(例如:button)
* 定时器回调函数 ——> this是 window
* ajax请求回调函数
* 生命周期回调函数
-->
<script>
document.getElementById("btn").οnclick=function(){ //dom事件回调函数
alert(this.innerHTML) //this是window
}
// 定时器
// 延时定时器
// 循环定时器
setTimeout(function(){ //定时器回调函数
alert("延时定时器已起动")
},2000)
var times=setInterval(function(){
alert("循环定时器已起动")
clearTimeout(times)
}, 4000);
</script>
</body>
</html>
05.回调函数——js高级
最新推荐文章于 2024-02-14 00:00:00 发布