demo:好比組件裏有個div寫的框框,點擊document body的背景色變紅,點擊div寫的框框沒效果javascript
componentDidMount(){ document.onclick = this.ChangeBodyBgcolor; } clickDiv= (e)=>{ e.nativeEvent.stopImmediatePropagation();//阻止冒泡 } ChangeBodyBgcolor= ()=>{ document.body.style.backgroundColor="red"; }