Overview:
The 3rd parameter, called Usecapture, is a Boolean value that is true or false. If it is true that the browser will use capture mode, false is bubbling, only in a certain situation, it is usually false, and it is the case that the target element has an ancestor element (a. ancestor element), and there is the same event response function
HTML fragment
<DivID= "Div1"style= "background:blue;width:100px; height:100px;"> <DivID= "Div2"style= "background:red;width:70px; height:70px;"> <DivID= "Div3"style= "background:yellow;width:50px; height:50px;"></Div> </Div> </Div>
JS Code
varODVI1 = document.getElementById (' Div1 ')), ODvi2= document.getElementById (' Div2 '), ODvi3= document.getElementById (' Div3 ');//123, 456, 345Odvi1.addeventlistener (' Click ', xx1,true); Odvi2.addeventlistener (' Click ', XX2,false); Odvi3.addeventlistener (' Click ', XX3,true);functionXx1 () {//BlueAlert (123);}functionXx2 () {//RedAlert (345);}functionXX3 () {//YellowAlert (456);}
Summarize:
Trigger a click event on Div3
Capture stage: Outside-"in the DIV1 to detect whether Usecapture is true, is to execute the program, div2 the same."
Target stage: Target to Div3, find Div3 is the mouse click node, so this is the target phase. If there is an event handler, execute the program, regardless of whether usecapture is true or false.
Bubbling stage: Inside-the external DIV2 detects if the Usecapture is false and executes the program. Div1