简体   繁体   English

得到一个来源 <video src> 在js脚本的html中

[英]getting a source for <video src> in html from js script

Im trying to display webms on my homepage in a random order every time someone access the homepage. 我每次有人访问主页时都试图以随机顺序在我的主页上显示网页。 I think, i got the random part done, my problem is, getting the path string into the source src="" of my html code my current take on this is: 我想,我完成了随机部分,我的问题是,将路径字符串放入我的html代码的源src =“”中,我当前对此采取的是:

HTML HTML

<div class="window" id="videos" style="display: none;">
      <div class="content">
        <center>
          <video controls width="500">
            <source id="random_webm" src="" type="video/webm">
            Your browser does not support HTML5 or .webm video, gramps.
          </video>
        </center>
      </div>
    </div>

JS JS

function random_webm(max) {
var src = ["videos/ship.webm", "videos/ira.webm"];
 return random_webm.src = src[Math.floor(Math.random() * src.length)];
src = rndwebm(3);
document.getElementById('random_webm').src = src.rndwebm(3); 

};

other things i tried https://pastebin.com/raw/3Sjpd0gW 我试过的其他东西https://pastebin.com/raw/3Sjpd0gW

concluision - how it works now: concluision - 现在如何运作:

<div class="window" id="videos" style="display: none;">
      <div class="header">
        <img class="icon" src="images/video.png">
            gnu.3gp     
        <div class="buttons">
          <button id= "videos" title="minimize" class="window_content" onclick="videos() ">_</button>
          <button>◽</button>
          <button id= "videos" title="minimize" class="window_content" onclick="videos() ">X</button>
        </div>
      </div>
      <div class="content">
        <center>
          <video controls width="500" id="random_webm" src="">
            <source type="video/webm">
            Your browser does not support HTML5 or .webm video, gramps.
          </video>
        </center>
      </div>
    </div>
function videos() {
  var src = ["videos/ship.webm", "videos/ira.webm"];
  document.getElementById('random_webm').src = src[Math.floor(Math.random() * src.length)];

  var x = document.getElementById("videos");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }

}

random_webm()

Try this code, and adapt it to your needs. 试试这段代码,并根据您的需求进行调整。

function random_webm() {
  var src = ["videos/ship.webm", "videos/ira.webm"];
  document.getElementById('random_webm').src = src[Math.floor(Math.random() * src.length)];
};

random_webm()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过video.js隐藏html中的视频源src - Hide video source src from html by video.js 如何从js文件中获取html脚本src值? - How to get html script src value from js file? 如何在JS脚本中向src源添加变量? - How to add variable to src source in JS script? 我发现了如何更改html5源代码的视频源(src),但在函数内部或使用内联JavaScript却得到了不同的结果 - I found how to change the video source (src) of an html5 source tag but am getting different results inside a function or with inline javascript 带有src的php脚本的html视频中的JS currentTime在Chrome上不起作用 - JS currentTime in html video with php script for src don't working on Chrome html从源获取视频将我重定向到首页 - html getting video from source redirecting me to frontpage Rails/JS - 延迟后更新视频源 src - Rails/JS - Update video source src after a delay html视频播放器并不总是从src中读取 - html video player not always read from src 从 iframe 中加载的 html 页面上的源脚本获取 Javascript 变量 - Getting Javascript variable from a source script on an html page loaded in an iframe JS 从视频元素(不是来自网络摄像头/麦克风等)捕获音频,因为视频 src 是外部的,因此出现 CORS 错误 - JS Capturing audio from a video element (Not from webcam/mic etc) Getting CORS error since video src is external
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM