Why is the event dispatched by window not captured by other elements?
问题 <body> <div id="d"></div> <script> document .getElementById("d") .addEventListener("test", () => console.log("div"), true); document.body.addEventListener("test", () => console.log("body"), true); window.addEventListener("test", () => console.log("window")); window.dispatchEvent(new CustomEvent("test")); </script> </body> If you run the code above, you will only see one output. 回答1: Custom event was only set for window. Try this in your script. <script> document.getElementById("d")