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 commonly used JavaScript events

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

Share

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

Editor to share with you what the commonly used JavaScript events are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

JavaScript event:

Events mean that when some components perform certain actions, the execution of some code is triggered.

Common events: attribute trigger time onabort image loading interrupted onblur element loss of focus onchange user change domain content onclick mouse click an object ondblclick mouse double click an object onerror when loading a document or image an error occurs onfocus element gets focus onkeydown a keyboard key is pressed onkeypress a keyboard key is pressed or an onkeyup keyboard key is released onload a page or image is finished Into loading onmousedown a mouse button is pressed onmousemove mouse is moved onmouseout mouse is moved from an element onmouseover mouse is moved over an element onmouseup a mouse button is released onreset reset button is clicked onresize window or frame is resized onselect text is selected onsubmit submit button is clicked onunload user exits page event operation

Bind event

Method 1: bind through the event attribute in the tag.

The next one / shows the first function up () {let img = document.getElementById ("img"); img.setAttribute ("src", "https://cache.yisu.com/upload/information/20211207/112/42675.jpg")} / / shows the second function down () {let img = document.getElementById (" img ") Img.setAttribute ("src", "https://cache.yisu.com/upload/information/20211207/112/42676.jpg%3Fw%3D425%26h%3D320&refer=http%3A%2F%2Fpic4.58cdn.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618451421&t=0310ddbd6f7cd840299b10dd314572c8")})

Method 2: bind through DOM element attributes.

Previous next shows the first function up () {let img = document.getElementById ("img"); img.setAttribute ("src", "https://cache.yisu.com/upload/information/20211207/112/42675.jpg")} let s = document.getElementById (" up "); s.onclick = up / / display the second function down () {let img = document.getElementById ("img"); img.setAttribute ("src", "https://cache.yisu.com/upload/information/20211207/112/42676.jpg%3Fw%3D425%26h%3D320&refer=http%3A%2F%2Fpic4.58cdn.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618451421&t=0310ddbd6f7cd840299b10dd314572c8")} let x = document.getElementById (" down ") X.onclick = down; are all the contents of this article entitled "what are the common JavaScript events?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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