简体   繁体   中英

Button onlick show alert box

I have a modal and after pressing the password update button, the modal should close and an alert box should appear on my homepage. however, the alert box will not appear when the page is first opened. how can I do it? Do you have any examples you can share?

If you are using the alerts provided by the browser, you have to add a EventListener to your button like:

yourCloseButton.addEventListener("click", () => {
  alert("The modal has been closed!");
});

Complementing Apollo79's answer, you can also use an inline event listener, but this is no longer recommended. There are some specific cases for this, but if you really don't need one, use Apollo79's answer instead.

<button id="urButton" onclick="alertAndDisappear()">

or

yourCloseButton.onclick = function(){}

which is equivalent to the first one.

Again, only use these if you really need them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM