Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add html element events

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to add html element event related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain something after reading this article on how to add html element events, let's take a look at it.

The details are as follows:

1. Through the HTML element attribute, which is in the html structure, add an attribute to the element to which you want to add the event.

The property name is' on' + event name.

For example, you want to bind a click event to element a with the following code:

Name

two。 Through object properties.

Objects refer to objects in the jDOM tree, and we all know that all html elements have a corresponding DOM element in DOM (document object type).

Adding an event to this DOM element is equivalent to method one, and so is the attribute name: on + event name

For example

Html structure:

Name

Js structure:

Document.getElementById ('n') .onclick = function () {/ / do something}

3. Add events through W3C snooping mode (standard mode)

W3C mode:

Elemennt.addEventListener (event name, handler reference, true | | false)

The event name here is a simple event name, and there is no need to add on. True means to capture the event in the event propagation phase, and false means to capture the event in the event bubbling phase. Generally, we set it to false!

4. Add events to the IE-specific intermediate model

IE mode:

Element.attachEvent ('on' + event name, handle function references)

Note: on is required for IE mode.

This is the end of the article on "how to add html element events". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to add html element events". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report