Home > Web Front-end > JS Tutorial > body text

Analysis of javascript event bubbling examples_javascript skills

WBOY
Release: 2016-05-16 15:59:32
Original
1278 people have browsed it

The example in this article describes javascript event bubbling. Share it with everyone for your reference. The specific analysis is as follows:

Event bubbling:

If element A is nested in element B, then when A is clicked, not only A's onclick event will be triggered, but B's onclick event will also be triggered,

The triggering sequence is "from inside to outside". Verification: add a table on the page, there is tr in the table, td in tr, and a p in td,

Add event response in p, td, tr, table

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>事件冒泡</title>
</head>
<body onclick="alert('body click');">
  <table onclick="alert('table click');">
    <tr onclick="alert('tr click');">
      <td onclick="alert('td click');">
        <input type="button" value="单击我" 
        onclick="alert('button click');" />
      </td>
    </tr>
  </table>
</body>
</html>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template