“Wydarzenie niestandardowe JS” Kod odpowiedzi

Trigger Event JavaScript

// Simple trigger event
document.querySelector(theElem).dispatchEvent(new Event('mouseover'))
Lively Leopard

Niestandardowe zdarzenia JavaScript z danymi

//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

JS Custom Event

// 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

Wydarzenie niestandardowe JS

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

Odpowiedzi podobne do “Wydarzenie niestandardowe JS”

Pytania podobne do “Wydarzenie niestandardowe JS”

Więcej pokrewnych odpowiedzi na “Wydarzenie niestandardowe JS” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu