JSFiddle - React, Tailwind, and code Playground

document 和 document.body 都绑定了 error 事件 但只有 document 被触发了这个事件

by danheberden

HTML

<a id="someElem">test</a>

JavaScript

$(function(){
    $( document ).bind( 'wat', function( evt ){
        console.log( 'Catched event by document', evt.namespace, evt );
    });
    
    $( 'body' ).bind( 'wat', function( evt ){
        console.log( 'Catched event by body', evt.namespace, evt );
    });

    console.log( "Trigger wat.custom" );
    $( '#someElem' ).trigger( 'wat.custom' );
    
    console.log( "Trigger error" );
    $( '#someElem' ).trigger( 'wat' );
});