怎么在html 通过点击按钮在同一页面相同位置切换视频?弄了一天了,希望有懂的朋友解答一下。
1条回答 默认 最新
coder2038 2023-05-28 15:25关注怎么在html 通过点击按钮在同一页面相同位置切换视频?弄了一天了,希望有懂的朋友解答一下。
```javascript <!DOCTYPE html> <html> <head> <title>切换视频示例</title> </head> <body> <h1>切换视频示例</h1> <!-- 第一个视频 --> <video id="video1" width="640" height="360" controls> <source src="video1.mp4" type="video/mp4"> Your browser does not support the video tag. </video> <!-- 第二个视频 --> <video id="video2" width="640" height="360" style="display:none" controls> <source src="video2.mp4" type="video/mp4"> Your browser does not support the video tag. </video> <!-- 切换视频的按钮 --> <button onclick="toggleVideo()">切换视频</button> <script type="text/javascript"> var video1 = document.getElementById("video1"); var video2 = document.getElementById("video2"); function toggleVideo() { if (video1.style.display === "none") { video1.style.display = "block"; video2.style.display = "none"; } else { video1.style.display = "none"; video2.style.display = "block"; } } </script> </body> </html>```
解决 无用评论 打赏 举报