What's the difference between cancelBubble and stopPropagation?

后端 未结 3 794
心在旅途
心在旅途 2020-11-30 00:20

Can anyone please tell me difference in usage of cancelBubble and stopPropagation methods used in javascript.

3条回答
  •  情书的邮戳
    2020-11-30 00:52

    For compatibility with IE8 and older use .cancelBubble if .stopPropogation() is undefined:

    if(ev.stopPropagation)ev.stopPropagation();
    else ev.cancelBubble=true; // where ev is an event object
    

    Read about in MSDN: http://msdn.microsoft.com/en-us/library/ff975961%28v=vs.85%29.aspx

提交回复
热议问题