* this is executed only when clicking the button *
<button onclick="alert('dd')">Click me</button>
动漫人物
浏览 113回答 1
1回答
偶然的你
您正在调用事件(function gigel...)(),因为调用返回任何内容a都不是函数。也a没有被调用,你会想要以下内容: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>或者,如果您想立即调用它并将其存储在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>