Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the commonly used JavaScript events

Shulou Source: shulou.com Published: 2022-06-02 07:04:26 09月10日 Update

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!

Tags: Event mouse element commonly used content image attribute article keyboard object button button mode focus user page previous not much code most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Linux MariaDB Shulou Technology