HTML5 视频 JavaScript
我没有 Javascript 经验,我有以下脚本在 Andriod 手机上播放视频文件,并且运行良好。
<script type="text/javascript">
function PlayMyVideo(arg) {
var myVideo = document.getElementById([arg]);
myVideo.play();
}
</script>
<video id="what" src="what.mp4" poster="" />
<input type="button" onclick="PlayMyVideo('what')" value="Play" />
我正在尝试即时编写标签:
<script type="text/javascript">
function PlayVideo() {
new_video = document.createElement('video');
new_video.setAttribute('scr', 'what.mp4');
new_video.play();
}
</script>
<input type="button" onclick="PlayVideo()" value="Play2" />
没有发生任何事情,将不胜感激您的建议。 提前致谢
I am not experienced in Javascript, I have the following script to play video files on Andriod phone, and it works fine.
<script type="text/javascript">
function PlayMyVideo(arg) {
var myVideo = document.getElementById([arg]);
myVideo.play();
}
</script>
<video id="what" src="what.mp4" poster="" />
<input type="button" onclick="PlayMyVideo('what')" value="Play" />
I am trying to write the tag on the fly:
<script type="text/javascript">
function PlayVideo() {
new_video = document.createElement('video');
new_video.setAttribute('scr', 'what.mp4');
new_video.play();
}
</script>
<input type="button" onclick="PlayVideo()" value="Play2" />
Nothing happen, would appreciate your suggestions.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“scr”拼写错误。它应该是“src”。
而且你应该在播放之前等待电影加载
'scr' is misspelled. It should be 'src'.
and also you should wait for the movie to load before play
好吧,您没有将新创建的标签附加到任何内容,因此它无法播放,因为它位于“内存”/“无效”中,而不是在屏幕上。
Well you're not appending the newly created tag to anything, so it can't play because it's in "memory"/"void", not on the screen.
您正在创建视频元素,您需要将其添加到 DOM 中,然后它才会可见,更多信息如下: http://www.javascriptkit.com/javatutors/dom2.shtml
you are creating the video element, you need to add it to the DOM before it will be visible, more info here: http://www.javascriptkit.com/javatutors/dom2.shtml