JSFiddle - React, Tailwind, and code Playground
document 和 document.body 都绑定了 error 事件 但只有 document 被触发了这个事件
by Ben Alman
HTML
<div>look @ console plz thx</div>
JavaScript
$('*').add(window).add(document).bind('custom', function( e ) {
console.log(e.type, this.nodeName || this, e.namespace);
});
$('*').add(window).add(document).bind('custom.a', function( e ) {
console.log('a', e.type, this.nodeName || this, e.namespace);
});
$('*').add(window).add(document).bind('custom.a.b', function( e ) {
console.log('a.b', e.type, this.nodeName || this, e.namespace);
});
console.log('\n== trigger "custom" ==');
// This should trigger all 3 bound events on each of
// DIV, BODY, HTML, document, window:
// custom DIV
// a custom DIV
// a.b custom DIV
// custom BODY
// a custom BODY
// a.b custom BODY
// custom HTML
// a custom HTML
// a.b custom HTML
// custom #document
// a custom #document
// a.b custom #document
// custom window
// a custom window
// a.b custom window
$('div').trigger('custom');
console.log('\n== trigger "custom.a" ==');
// This should trigger only custom.a and custom.a.b bound
// events on each of DIV, BODY, HTML, document, window
// a custom DIV
// a.b custom DIV
// a custom BODY
// a.b custom BODY
// a custom HTML
// a.b custom HTML
// a custom #document
// a.b custom #document
// a custom window
// a.b custom window
$('div').trigger('custom.a');
console.log('\n== trigger "custom.a.b" ==');
// This should trigger only custom.a.b bound events on
// each of DIV, BODY, HTML, document, window
// a.b custom DIV
// a.b custom BODY
// a.b custom HTML
// a.b custom #document
// a.b custom window
$('div').trigger('custom.a.b');