js 回撥 callback

丁焕轩發表於2024-03-28
<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>

相關文章