Test adding events: firefox uses addEventListener,i">
First introduce the common method of adding events in js, the specific content is as follows
测试添加事件:firefox使用addEventListener,ie使用attachEvent
点击此p标签,绑定了2个弹出事件
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事件绑定
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!