JavaScript events:
Commonly used events:
Event ActionsBinding Events Method 1 : Bind through the event attribute in the tag. <body> <img id="img" src="upload/2022/web/u=1582373193,2567665585&fm=26&gp=0.jpg"> <br/> <button id="up" onclick="up()">Previous</button> <button id="down" onclick="down()">Next</button> </body> <script> // Display the first function up() { let img = document.getElementById("img"); img.setAttribute("src", "upload/2022/web/u=1582373193,2567665585&fm=26&gp=0.jpg") } // Display the second image function down() { let img = document.getElementById("img"); img.setAttribute("src", "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic4.58cdn.com.cn%2Fp1%2Fbig%2Fn_v26f22be8b05a74c42b8f9dfb859480186.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") } </script> Method 2 : Binding through DOM element attributes. <body> <img id="img" src="upload/2022/web/u=1582373193,2567665585&fm=26&gp=0.jpg"> <br/> <button id="up">Previous</button> <button id="down">Next</button> </body> <script> // Display the first function up() { let img = document.getElementById("img"); img.setAttribute("src", "upload/2022/web/u=1582373193,2567665585&fm=26&gp=0.jpg") } let s = document.getElementById("up"); s.onclick = up; // Display the second image function down() { let img = document.getElementById("img"); img.setAttribute("src", "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic4.58cdn.com.cn%2Fp1%2Fbig%2Fn_v26f22be8b05a74c42b8f9dfb859480186.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; </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Solution to inconsistent display of cursor size in input box
>>: How to package the docker image, push it to the remote server and deploy it to k8s
There was a problem when installing the compresse...
The first time I wrote a MySQL FUNCTION, I kept g...
This article example shares the specific code of ...
<br />Related articles: innerHTML HTML DOM i...
Introduction: Compared with traditional image ver...
Html semantics seems to be a commonplace issue. G...
Scenario simulation: Some domestic companies need...
This article shares the specific code of videojs+...
At first, I wanted to modify the browser scroll b...
Detailed tutorial on downloading and installing M...
This article uses an example to describe the solu...
Many web designers are confused about the width of...
Table of contents Configuration parsing Service C...
1. Cleaning before installation rpm -qa | grep jd...
1. Download MySQL Click on the official website d...