There is a data method in jq, which binds relevant data to DOM elements. When an event is bound to the dom using the jq method, a corresponding time list will be generated
You can see the following example (please view it in firefox because objects in firefox support toSource())
win.each = function( object, callback, args ) {
var name, i = 0, length = object.length;
if ( args ) {
if ( length === undefined ) {
for ( name in object )
if ( callback.apply( object[ name ], args ) === false )
break;
} else
for ( ; i < length; )
if ( callback.apply( object[ i ], args ) === false )
break;
} else {
if ( length === undefined ) {
for ( name in object )
if ( callback.call( object[ name ], name, object[ name ] ) === false )
break;
} else
for ( var value = object[0];
i < length && callback.call( value, i, value ) !== false; value = object[ i] ){}
}
return object;
}
In jq is the add method in jQuery.event
Some functions are implemented in the add method
Get the events of the element and handle the data bound to these two data
events stores a list of events
The format is as follows
{
click: [{handler:function(){},type:"click",guid:'xx'}.....],
mouse:[...]
}
handle is the executed function
(All execution functions are the same. They traverse the event list and execute the corresponding event)
Then traverse the types because multiple events can be bound
The callback function will also give several attributes
Assume the callback function is handler
handler.guid = gevent.guid
handler.type = name
name should be considered a special name for easy deletion
For example
$('#xx')
.bind('click',function(){})
.bind('click.d',handler)
The name is d
When deleting, you can only delete the d event without deleting the click event above
Finally, the event is bound to the element, but the functions executed are all
function(){
gevent.handle.apply(arguments.callee.elem, arguments);
});
以上内容只是自己的一些理解,水平有限,难免有错,望指正...