我真的是JavaScript的新手,因此我不知道如何嵌入每天都会改变的视频。示例视频1用于星期一,视频2用于星期二类似的东西。我创造了类似于这种情况的东西,但仅用于图像。不知道我将如何在视频中制作它。谁能帮我? PLS。谢谢=)
这是我的示例方法,根据您在电脑上设置的日期及其工作效果,图像会发生变化。
<!DOCTYPE html>
<html>
<title></title>
<head>
<script type="text/javascript">
window.onload = function(){chgDailyVideo();}
function chgDailyVideo()
{
var vid_array = new Array();
vid_array[0] = "sundaypic.jpg"
vid_array[1] = "mondaypic.jpg"
vid_array[2] = "tuesdaypic.jpg"
vid_array[3] = "wednesdaypic.jpg"
vid_array[4] = "thursdaypic.jpg"
vid_array[5] = "fridaypic.jpg"
vid_array[6] = "saturdaypic.jpg"
var txt_array = new Array();
txt_array[0] = "Hi Im Sunday"
txt_array[1] = "Hi Im Monday"
txt_array[2] = "Hi Im Tuesday"
txt_array[3] = "Hi Im Wednesday"
txt_array[4] = "Hi Im Thursday"
txt_array[5] = "Hi Im Friday"
txt_array[6] = "Hi Im Saturday"
var d = new Date();
var i = d.getDay();
document.getElementById("dailyVid").src = vid_array[i];
document.getElementById("dailyTxt").innerHTML = txt_array[i];
}
</script>
<style type="text/css"></style>
</head>
<body>
<p id = "dailyTxt">Hi I'm Sunday</p>
<img src = "sundaypic.jpg" alt"daily vid" title = "daily pic" id="dailyVid"/>
</body>
</html>
答案 0 :(得分:1)
只需使用<video>
代码而不是<img>
,并让最后两行保持不变:
document.getElementById("dailyVid").src = vid_array[i];
document.getElementById("dailyTxt").innerHTML = txt_array[i];
// the above line will show up in case <video> isn't supported.
请注意,您只能使用以扩展程序ogg,mp4等结尾的视频,而上述内容是您嵌入视频的最简单形式。请参阅链接以了解更多信息。