Javascript CustomEvent detail not getting passed

前端 未结 3 1897
别那么骄傲
别那么骄傲 2021-02-08 10:30

I am trying to create a custom javascript event. The event works and fires correctly, but the \'detail\' object that I\'m passing it is not available.

Here\'s the code i

3条回答
  •  被撕碎了的回忆
    2021-02-08 11:16

    obj.addEventListener("eventName", function(e) {
    console.log(e.your_property)
    })
    
    var event = new CustomEvent("eventName");
    event.your_property = { key: "value" };
    
    obj.dispatchEvent(event);
    

    You can create properties in your CustomEvent, when you dispatch you are sending it.

提交回复
热议问题