簡體   English   中英

得到一個來源 <video src> 在js腳本的html中

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

我每次有人訪問主頁時都試圖以隨機順序在我的主頁上顯示網頁。 我想,我完成了隨機部分,我的問題是,將路徑字符串放入我的html代碼的源src =“”中,我當前對此采取的是:

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

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); 

};

我試過的其他東西https://pastebin.com/raw/3Sjpd0gW

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()

試試這段代碼,並根據您的需求進行調整。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM