js 回调 callback

<html>
<head>
<title>按钮点击事件示例</title>
<script>
function a(callback) {      
   console.log("执行函数a!");   
   console.log("调用回调函数");   
   callback(); // 调用回调函数
}

function b(){ console.log("回调函数b"); }   

function c() { console.log("回调函数c"); }   
  
function execute(){ a(b); a(c); }

<!-- execute(); -->
</script>
</head>
<body>
<button onclick = "execute()">回调函数</button>
</body>
<html>

 

posted @ 2024-03-28 13:24  丁焕轩  阅读(7)  评论(0编辑  收藏  举报