JavaScript Event Flow Tutorial and example application

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.