Javascript CustomEvent detail not getting passed

前端 未结 3 1900
别那么骄傲
别那么骄傲 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:11

    I found the following commit: https://github.com/jquery/jquery/commit/a90ff8c8c79bfcc32afd340a12f016f20a31d8b6

    This fix is in jQuery's compat branch and should be fixed as of jQuery 3.0.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-08 11:21

    You need to access the originalEvent property for the details

    console.log(e.originalEvent.detail);
    
    0 讨论(0)
提交回复
热议问题