如何使用jquery动态更改视频,源路径存储在数据库中,文件存储在文件系统中

2024-04-26 07:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我将视频文件存储在文件系统中,并将路径存储在数据库中。我可以使用js和jquery显示视频。我想在单击列表。但是只有第一个视频是在这里玩这是我的密码

<script type="text/javascript"> function fn() { var player = document.getElementById("videoclip"); var mp4Vid = document.getElementById("mp4video"); var a = '/site_media/media/'; var b = document.getElementById("btn").value; var c = a + b; player.pause(); document.getElementById("mp4video").src = c; player.load(); player.play(); } </script>
<body>
  <div align="right">
  <table border='1'>
  <tr><th>slno</th> <td>Filename</td></tr>
  {% for i in total %}//total contains the video paths(python)
  <tr>
  <td>{{ forloop.counter }}</td>
  <td align="center">
  <input type="button" onclick="fn()" id="btn" value="{{ i.vid }}"/>
  </td>
  </tr>
  {% endfor %}
  </table>
  </div>

<div align="center">
<video id="videoclip" width="320" height="240" controls='controls' autoplay>
 <source id= "mp4video" src="/site_media/media/upload/vid2.mp4" type="video/mp4">
  </video> <br></div>
</body>

Tags: divid视频varvideotypescriptdocument
1条回答
网友
1楼 · 发布于 2024-04-26 07:34:11

id必须是唯一的本文件:你知道吗

<input type="button" onclick="fn(this)" id="{{ i.vid }}" value="{{ i.vid }}"/>

然后在jquery中代码:-你知道吗

function fn(dv) {
  var player = document.getElementById("videoclip");
  var mp4Vid = document.getElementById("mp4video");
  var a = '/site_media/media/';
  var b = $(dv).attr('id');
  var c = a + b;
  player.pause();
  document.getElementById("mp4video").src = c;
  player.load();
  player.play();
}

相关问题 更多 >