In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces what are the event handling methods in javascript, which can be used for reference by interested friends. I hope you will gain a lot after reading this article.
Javascript event handling methods are: 1, add events to the event attribute of the tag, syntax "; 2, use the event attribute of the event source to bind the event handler function, syntax" event source object .on event name = event handler function ".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The method of javascript event handling
Method 1. Add an event to the event attribute of the tag
Bind the handler using the event attribute of the HTML tag. 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.
Example:
Function printName () {var name = "Zhang San"; alert (name);}
Method 2. Use the event attribute binding handler of the event source
One of the ways to separate HTML from JS is to bind the event handler by using the event property of the event source, in the following format:
Obj.on event name = event handler
Obj in the format is the event source object. The bound event program is usually a definition statement of an anonymous function, or a function name.
Example of an event property binding handler for an event source:
OBtn.onclick = function () {/ / oBtn is the event source object whose click event is bound to an anonymous function definition alert ('hi')}
Example: use the event property of the event source to bind the event handler.
_ window.onload = function () {/ / window load event binds an anonymous function / / defines a function named fn function fn () {alert ('hello');} / / gets the event source object var oBtn1 = document.getElementById ("btn1"); var oBtn2 = document.getElementById ("btn2") / / bind an anonymous function oBtn1.onclick = function () {alert ("hi");} / / bind a function name oBtn2.onclick = fn;} Thank you for reading this article carefully. I hope the article "what are the event handling methods in javascript" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.