A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/ja/docs/Web/API/HTMLDialogElement/close_event below:

HTMLDialogElement: close イベント - Web API

HTMLDialogElement: close イベント

Baseline Widely available

close イベントは HTMLDialogElement オブジェクト上で、これが表すダイアログ (<dialog>) が閉じられたときに発生します。

このイベントはキャンセル不可で、バブリングしません。

構文

このイベント名を addEventListener() などのメソッドで使用したり、イベントハンドラープロパティを設定したりします。

addEventListener("close", (event) => {});

onclose = (event) => {};
イベント型

一般的な Event です。

例 ライブ例 HTML
<dialog class="example-dialog">
  <form method="dialog">
    <button>method="dialog" で閉じる</button>
  </form>
  <button class="close">.close() メソッドで閉じる</button>
  <p>または <kbd>Esc</kbd> キーを押してください</p>
</dialog>

<button class="open-dialog">ダイアログを開く</button>

<div class="result"></div>
button,
div {
  margin: 0.5rem;
}
JavaScript
const result = document.querySelector(".result");

const dialog = document.querySelector(".example-dialog");
dialog.addEventListener("close", (event) => {
  result.textContent = "ダイアログが閉じました";
});

const openDialog = document.querySelector(".open-dialog");
openDialog.addEventListener("click", () => {
  dialog.showModal();
  result.textContent = "";
});

const closeButton = document.querySelector(".close");
closeButton.addEventListener("click", () => {
  dialog.close();
});
結果 仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4