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

What are the methods of javascript event binding

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the methods of javascript event binding, the article is very detailed, has a certain reference value, interested friends must read it!

1. Bind with the statement "object .on event name = function () {Code}".

OBtn.onclick = function () {/ / oBtn is the event source object whose click event is bound to an anonymous function definition alert ('hi')}

2. Use the "event source .addEventListener (event name, event handler name, capture or not);" statement to bind.

Document.addEventListener ('click',fn1,false); / / click event binding fn1 function to achieve event bubbling document.addEventListener (' click',fn2,true); / / click event binding fn2 function to achieve event capture

3. Use the "onclick" attribute in the HTML tag to bind the event.

It is important to note that when you use the event attribute of the HTML tag to bind the event handler, the script code in the event attribute cannot contain a function declaration, but can be a function call or a series of script code separated by semicolons.

The above is all the content of the article "what are the methods of javascript event binding?" Thank you for reading! Hope to share the content to help you, more related knowledge, 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

Development

Wechat

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

12
Report