浅谈jQuery事件绑定原理

2020-05-22 17:11:35易采站长站整理

this.timeStamp = now();
// Mark it as fixed
this[expando] = true;
}
function returnFalse(){
return false;
}
function returnTrue(){
return true;
}
setEvent.prototype = {
preventDefault: function() {
var e = this.originalEvent;
if( !e )
return;
// if preventDefault exists run it on the original event
if (e.preventDefault)
e.preventDefault();
// otherwise set the returnValue property of the original event to false (IE)
e.returnValue = false;
},
stopPropagation: function() {
var e = this.originalEvent;
if( !e )
return;
// if stopPropagation exists run it on the original event
if (e.stopPropagation)
e.stopPropagation();
// otherwise set the cancelBubble property of the original event to true (IE)
e.cancelBubble = true;
},
stopImmediatePropagation:function(){
this.isImmediatePropagationStopped = returnTrue;
this.stopPropagation();
},
isImmediatePropagationStopped: returnFalse
};
})(document);
var $ = function(id){return document.getElementById(id)}
var a = function(){alert(1)}
window.onload = function(){
gevent.add($(‘xx’),’click’,a);
gevent.add($(‘xx’),’click’,function(){alert(1)});
gevent.add($(‘xx’),’click’,function(){alert(2)});
gevent.add($(‘xx’),’click’,function(){alert(3)});
gevent.add($(‘xx’),’click.xx’,function(){alert(4)});
}
</script>
</body>
</html>

以上内容只是自己的一些理解,水平有限,难免有错,望指正…