使用jQuery来控制视频标签 [英] Use jQuery to control video tag
本文介绍了使用jQuery来控制视频标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
收集REL并发送给这是没有问题的......但从jQuery触发元素的加载和播放功能需要什么?
这是我到目前为止:
$ b $
$(function(){
$('a.componentLink')。click(function(){
event.preventDefault ();
var vidURL = $(this).attr('rel');
$('#myVideo> source')。attr('src',vidURL);
$('#myVideo')。load();
$('#myVideo')。play();
})
});
ATM,它不会播放...我假设jQuery本身不能访问播放功能......但必须有解决方法。
解决方案
您需要调用。 play()
在元素本身上,而不是在jQuery选择上。执行以下操作:
$(function(){
$('a.componentLink')。click(function (){
event.preventDefault();
var vidURL = $(this).attr('rel');
$('#myVideo')。attr('src', vidURL);
var video = $('#myVideo')。get(0);
video.load();
video.play();
})
});
So, I want to use a jQuery function to collect a URL from a link's REL, and pass it to a element.
Collecting the REL and sending it to the is no problem... but what's required to trigger the element's load and play functions, from jQuery?
Here's what I have so far:
$(function(){
$('a.componentLink').click(function() {
event.preventDefault();
var vidURL = $(this).attr('rel');
$('#myVideo > source').attr('src', vidURL);
$('#myVideo').load();
$('#myVideo').play();
})
});
ATM, it doesn't play... I assume jQuery doesn't natively have access to the play function... but there must be a way around that.
解决方案
You need to call .play()
on the element itself, not on the jQuery selection. Do the following:
$(function(){
$('a.componentLink').click(function() {
event.preventDefault();
var vidURL = $(this).attr('rel');
$('#myVideo').attr('src', vidURL);
var video = $('#myVideo').get(0);
video.load();
video.play();
})
});
这篇关于使用jQuery来控制视频标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文