我可以使用javascript动态更改视频的来源吗? [英] Can I use javascript to dynamically change a video's source?
本文介绍了我可以使用javascript动态更改视频的来源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用JS更改视频来源?
How can I change a video's source using JS?
<video id="myVideoTag" width="670" height="377" autoplay="true" controls="controls">
<source src="http://www.test.com/test.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
推荐答案
当然,你可以设置<$ c $ 来源
元素上的c> src 属性:
Sure, you can just set the src
attribute on the source
element:
document.querySelector("#myVideoTag > source").src = "http://example.com/new_url.mp4"
或使用jQuery而不是标准DOM方法:
Or using jQuery instead of standard DOM methods:
$("#myVideoTag > source").attr("src", "http://example.com/new_url.mp4")
这篇关于我可以使用javascript动态更改视频的来源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文