[Edge]。→、
新しい Event を生成します。
この方法で作成されたイベントは合成イベントと呼ばれ、ブラウザーによって発行されたイベントとは対照的となっており、スクリプトから配信することができます。
type | 文字列で、イベントの名前を表します。 | ||||||||
---|---|---|---|---|---|---|---|---|---|
options | 省略可。以下のプロパティを持ったオブジェクトです。
|
新しい Event オブジェクトです。
// create a look event that bubbles up and cannot be canceled const evt = new Event("look", {"bubbles":true, "cancelable":false}); document.dispatchEvent(evt); // event can be dispatched from any element, not only the document myDiv.dispatchEvent(evt);
HTML:
<SPAN id=IdSpan onclick="alert(event.type)">SPAN要素。ここでクリック…</SPAN>
JavaScript:
eve=new Event("click"); //clickイベントを生成。 IdSpan.dispatchEvent(eve); //SPAN要素でそのclickイベントを起動させる。