如何從 txt 檔案中讀取 url 并在 html 中使用?我在 .txt 檔案中有一個視頻源網址。如何在 html 檔案中使用此 url?有時我想編輯 .txt 檔案中的視頻源。
在 /videosrc.txt 中:
http://www.videoexaple.com/videos/video.mp4
在 /index.html 檔案中:
<html>
<head>
<title></title>
</head>
<body>
<video id="video">
<source id="videosource" src=" -url from /video.txt- " type='video/mp4'>
</video>
</body>
</html>
uj5u.com熱心網友回復:
我建議您閱讀一下: https ://www.w3schools.com/php/php_file_open.asp 查看第一個示例,您可以看到檔案的輸出。
這向您展示了如何訪問檔案中的資訊。然后只需將資料放在正確的位置即可。
uj5u.com熱心網友回復:
最簡單的方法是在與 html 檔案相同的檔案夾中擁有一個擴展名為 .js 的檔案 - 例如 video.js
它看起來像這樣:
const videoURL = "https://www.videoexaple.com/videos/video.mp4";
然后在你的 HTML 中有
<script src="video.js"></script>
<script>
window.addEventListener("DOMContentLoaded",function() {
document.getElementById("videosource").src = videoURL;
})
</script>
uj5u.com熱心網友回復:
嘗試這個
fetch('file.txt')
.then(response => response.text())
.then(text => { document.getElementById("videosource ").src =text;})
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446497.html
標籤:javascript html 网址 文本
