React 阻止事件冒泡

簡單來講php

 e.stopPropagation() 能夠阻止合成事件之間的冒泡  不能夠阻止合成事件到原生事件的冒泡react

 

由於React委託的document 和原生document不是同一個事物jquery

e.stopPropagation()阻止的只是到react對應document事件

而當事件觸發時,會向 react和原生document兩個方向傳遞io

 

若是要阻止這兩種冒泡,得寫上下面兩句,就真正阻止了冒泡event

e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
 
stopImmediatePropagation()的做用 詳見   http://www.runoob.com/try/try.php?filename=tryjquery_event_stoppropagation
 
至於爲何
e.nativeEvent.stopPropagation(); 不可行
而e.nativeEvent.stopImmediatePropagation();可行  還不太清楚
相關文章
相關標籤/搜索