Javascript 按查询字符串加载mp4视频
我需要通过查询字符串加载mp4视频。使用jquery我的代码不会更新视频源。如果我将示例视频url放在html5源id中,它将在没有JQuery的情况下工作。我的任务是打开页面并加载正确的视频 问题是代码没有看到JS源代码。。当我不应该使用时,还使用$定义了变量。现在它起作用了Javascript 按查询字符串加载mp4视频,javascript,jquery,html,video,Javascript,Jquery,Html,Video,我需要通过查询字符串加载mp4视频。使用jquery我的代码不会更新视频源。如果我将示例视频url放在html5源id中,它将在没有JQuery的情况下工作。我的任务是打开页面并加载正确的视频 问题是代码没有看到JS源代码。。当我不应该使用时,还使用$定义了变量。现在它起作用了 <video id='videoPlayer' width="640" height="480" controls="controls"> <source id='mp4Source'
<video id='videoPlayer' width="640" height="480" controls="controls">
<source id='mp4Source' src="" type="video/mp4" />
</video>
<script src="jquery.min.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">-->
<script>
$(document).ready(function () {
// theVid will be populated by query string, for testing it's hard coded.
//var theVid = 'http://html5demos.com/assets/dizzy.mp4';
var theVid = 'http://techslides.com/demos/sample-videos/small.mp4';
var player = document.getElementById('videoPlayer');
var mp4Vid = document.getElementById('mp4Source');
player.pause();
// Now simply set the 'src' attribute of the mp4Vid variable!!!!
// (...using the jQuery library in this case)
$(mp4Vid).attr('src', theVid);
player.load();
//player.show();
player.play();
});
$(文档).ready(函数(){
//VID将由查询字符串填充,用于测试它的硬编码。
//var theVid=http://html5demos.com/assets/dizzy.mp4';
var theVid=http://techslides.com/demos/sample-videos/small.mp4';
var player=document.getElementById('videoPlayer');
var mp4Vid=document.getElementById('mp4Source');
player.pause();
//现在只需设置mp4Vid变量的'src'属性!!!!
//(…在本例中使用jQuery库)
$(mp4Vid).attr('src',theVid);
player.load();
//player.show();
player.play();
});
您没有将源代码设置为列出的html。试试看。在这种情况下,我在发帖后大约一个小时就找到了答案,因为我有8个小时无法回答,所以我只是用工作代码编辑了它。VID是URL工作的源。我的问题是,它没有看到底部的脚本源代码,将其移动到顶部会有所帮助。
$('#mp4Source').attr('src', theVid);