“Acara Kustom JS” Kode Jawaban

Acara Kustom JavaScript dengan Data

//Listen for the event
window.addEventListener("MyEventType", function(evt) {
    alert(evt.detail);
}, false);

//Dispatch an event
var evt = new CustomEvent("MyEventType", {detail: "Any Object Here"});
window.dispatchEvent(evt);
Scriper

Acara Kustom JS

// create a custom event
const custom_event = new CustomEvent("custom_event_name", {
	// whether or not the event 'bubbles' up the DOM tree
	bubbles: true,
	// special property allowing you to provide additional information
	detail: {
		
	}
});

// to add an event listener
element.addEventListener("custom_event_name", function() {
	// event handler
});

// to trigger an event
element.dispatchEvent(custom_event);
MattDESTROYER

Acara Kustom JS

const eventDetails = {
  'id': elemId
}
document.dispatchEvent (
  new CustomEvent('myCustomEvent', {'detail': eventDetails})
)
Lively Leopard

Contoh acara khusus

		 const btn1 = document.getElementById('btn1');

			   btn1.addEventListener('boo', function () {
			          alert('Button1 said Boo');
			   });
			   
			   
  			 const btn2 = document.getElementById('btn2');

  			   btn2.addEventListener('boo', function () {
  			          alert('Button 2 said Boo');
  			   });
			   			  const clickEvent = new Event('boo');
			   btn1.dispatchEvent(clickEvent);

			  btn2.dispatchEvent(clickEvent);
Javasper

Jawaban yang mirip dengan “Acara Kustom JS”

Pertanyaan yang mirip dengan “Acara Kustom JS”

Lebih banyak jawaban terkait untuk “Acara Kustom JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya