Test adding events: firefox uses addEventListener,i"> Detailed explanation of how to use event attributes to bind event functions in javascript-JS Tutorial-php.cn

Detailed explanation of how to use event attributes to bind event functions in javascript

伊谢尔伦
Release: 2017-07-22 16:04:27
Original
1488 people have browsed it

First introduce the common method of adding events in js, the specific content is as follows


     
  

测试添加事件:firefox使用addEventListener,ie使用attachEvent
点击此p标签,绑定了2个弹出事件

Copy after login

The common way of binding events in js:

How to bind events: Use event attributes to bind event functions
Advantages:

1. Complete the separation of behaviors
2. It is convenient to operate the object in question, because the function is Appearing as an attribute of on***, you can directly use this to refer to the object in question.
3. It is convenient to read the event object. When the event is triggered, the system automatically passes the event object to the event function. Pass it one by one


     JS事件绑定   
  

Copy after login

The above is the detailed content of Detailed explanation of how to use event attributes to bind event functions in javascript. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!