JavaScript Event Flow Tutorial and example application
When a page element triggers an event, the container for that element and the entire page follow a specific
The sequence is the triggering event of the element, and the order of event propagation is called the event stream.
I. Classification of event streams
1. Bubbling event (all browsers are supported by the Web-based standard)
Triggered by a clear event source to the most uncertain event source, in turn, there is an inward-to-outer.
2. Capture-type event (ie does not support standard Firefox)
An indeterminate event source to a definite event source is then triggered downward, by an outward inward.
AddEventListener (event, handling function, false)
AddEventListener (event, handler function, True)
Second, block the flow of events
Ie:
The event object. Cancelbubble=true;
Ff:
The event object. Stoppropagation ();
Iii. objects of the target event source
IE: Event object. srcelement
FF: Event object. Target
Cases:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style type= "Text/css" >
Table {
margin:0 Auto;
}
td{
Text-align:center;
}
</style>
<script type= "Text/javascript" >
Window.onload = function () {
var tbl = document.getElementById ("tbl");
Tbl.ondblclick = function (e) {
var VC = e | | window.event;
var ov = Vc.srcelement | | Vc.target;
if (Ov.nodename = = "TH") {
Return
}
var oldstr = ov.innerhtml;
var txts = document.createelement ("input");
Txts.type = "text";
ov.innerhtml = "";
Ov.appendchild (txts);
Txts.focus ();
Txts.onblur = Txts.ondblclick = Txts.onkeydown = function (e) {
var VC = e | | window.event;
if (Vc.type = = "Blur" | | (Vc.type = = "KeyDown" && Vc.keycode = = "13")) {
var str;
if (txts.value.trim () = = "") {
str = OLDSTR;
}else{
str = Txts.value;
}
Ov.removechild (txts);
ov.innerhtml = str;
}
}
}
}
</script>
<body>
<table id= "TBL" border= "1" width= "0" cellpadding= "cellspacing=" >
<caption> Student Transcripts </caption>
<tr>
<th> name </th>
<th> Age </th>
<th> Sex </th>
<th> Subjects </th>
<th> score </th>
</tr>
<tr >
<td> Zhang San </td>
<td>21</td>
<td> Men </td>
<td>JavaScript</td>
<td>86</td>
</tr>
<tr>
<td> John Doe </td>
<td>22</td>
<td> Women </td>
<td>CSS</td>
<td>94</td>
</tr>
<tr>
<td> Sophomore </td>
<td>20</td>
<td> Women </td>
<td>HTML</td>
<td>89</td>
</tr>
</table>
</body>
JavaScript Event Flow Tutorial and example application