1 回答

TA貢獻(xiàn)1841條經(jīng)驗 獲得超3個贊
您正在調(diào)用事件(function gigel...)(),因為調(diào)用返回任何內(nèi)容a都不是函數(shù)。也a沒有被調(diào)用,你會想要以下內(nèi)容:
let a = (function gigel() {
alert("IIFE");
});
* this is executed immediately as the page loads*
<button onclick="a()">Click me</button>
* this is executed only when clicking the button *
<button onclick="alert('dd')">Click me</button>
或者,如果您想立即調(diào)用它并將其存儲在a:
let a = (function gigel() {
alert("IIFE");
return gigel;
})();
* this is executed immediately as the page loads*
<button onclick="a()">Click me</button>
* this is executed only when clicking the button *
<button onclick="alert('dd')">Click me</button>
添加回答
舉報