The trigger order of true is always before false; if multiple are true, the trigger of the outer layer prevails over the inner layer; if multiple are false, the trigger of the inner layer prevails over the outer layer.
Example
If you click the mouse on d3, the event stream is like this:
The capture phase checks whether there are Event Handlers whose useCapture is true at p1. If so, it executes the program and then processes p2 in the same way.
When the target stage is at p3, it is found that p3 is the node clicked by the mouse. Therefore, this stage is the target stage. If there is an event processing program, execute this program, regardless of whether useCapture is true or false.
In the bubble stage, p2 checks whether there are Event Handlers whose useCapture is false. If so, execute the program and then process p1 in the same way.
AddEventListener has three parameters: the first parameter indicates the event name (not including on, such as "click"); the second parameter indicates the function for Receiving Event processing; the third parameter is useCapture, this article will explain it.
Click here.
Var outDiv = document. getElementById ("outDiv ");
Var middleDiv = document. getElementById ("middleDiv ");
Var inDiv = document. getElementById ("inDiv ");
Var info = document. getElementById ("info ");
OutDiv. addEventListener ("click", function () {info. innerHTML + = "outDiv" +"
";}, False );
MiddleDiv. addEventListener ("click", function () {info. innerHTML + = "middleDiv" +"
";}, False );
InDiv. addEventListener ("click", function () {info. innerHTML + = "inDiv" +"
";}, False );
The above is the code we tested. Based on the display of info, we can determine the trigger order. There are three addEventListener options, and the optional values of useCapture are true and false, SO 2*2*2, we can get 8 different programs.
• When all values are false, the trigger sequence is inDiv, middleDiv, and outDiv;
• When all values are true, the trigger sequence is outDiv, middleDiv, and inDiv;
• When outDiv is true and others are false, the trigger sequence is outDiv, inDiv, and middleDiv;
• If middleDiv is set to true and other values are set to false, the trigger sequence is middleDiv, inDiv, and outDiv;
•......
Finally, the following conclusions are drawn:
• The trigger sequence of true is always before false;
• If multiple triggers are true, the triggering of the outer layer prevails over the inner layer;
• If multiple triggers are false, the triggering of the inner layer prevails over the outer layer.