kafpliz Asked:2022-06-28 23:57:23 +0000 UTC2022-06-28 23:57:23 +0000 UTC 2022-06-28 23:57:23 +0000 UTC 如何在按钮单击上更改视频[关闭] 772 您可以丢弃当您单击按钮时,视频会发生变化的 js 代码。假设:您访问该站点,那里有第一个系列,但旁边有带有系列的按钮,例如“1 系列”、“2 系列”等。并且通过按第 2 系列的按钮,打开第 2 集,当按“第 3 系列”按钮时,打开第 3 集。 javascript 0 个回答 Voted Best Answer Senje 2022-06-29T12:59:33Z2022-06-29T12:59:33Z 这是如何做到这一点的示例。 var videos = [ "1.mp4", "2.mp4", "3.mp4", "4.mp4", ]; function videoChange(id) { var video = document.getElementById("video"); var source = document.getElementById("source"); source.src = videos[id]; video.appendChild(source); video.load(); video.pause(); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="script.js"></script> <link rel="stylesheet" href="style.css"> </head> <body> <div> <video width="400" height="300" controls="controls" id="video"> <source src="1.mp4" id="source"> </video> </div> <input type="button" onclick="videoChange(0)" value="1"> <input type="button" onclick="videoChange(1)" value="2"> <input type="button" onclick="videoChange(2)" value="3"> <input type="button" onclick="videoChange(3)" value="4"> </body> </html>
这是如何做到这一点的示例。