动态创建元素的视频addEventListener
您是否知道为什么我收到错误“无法创建 null 事件侦听器”:
var my;
my.newVidObj = document.createElement('video');
my.newVidObj.src = "vid-source.webm";
my.newVidObj.load();
my.newVidObj.addEventListener("play", function() {
// Do something
}, false);
另外,有没有办法在 jquery 对象上使用视频标记方法(例如,通过 jquery 创建视频标记) ?
我编辑了以下答案,使其正确,但需要经过同行评审。这是解决方案:
var vid = $("<video />", {
id: "my-HTML5-video",
src: "video.webm"
}).bind("play", function(){
alert('test');
}).appendTo("body")[0].play();
Do you have any idea why I'm getting an error "Can't create event listener of null" from this:
var my;
my.newVidObj = document.createElement('video');
my.newVidObj.src = "vid-source.webm";
my.newVidObj.load();
my.newVidObj.addEventListener("play", function() {
// Do something
}, false);
Also, is there any way to use video tag methods on jquery objects (creating the video tag via jquery, for example)?
I edited the below answer to be correct, but it needs to be peer reviewed. Here is the solution:
var vid = $("<video />", {
id: "my-HTML5-video",
src: "video.webm"
}).bind("play", function(){
alert('test');
}).appendTo("body")[0].play();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这些链接:
http ://www.chipwreck.de/blog/2010/03/01/html-5-video-dom-attributes-and-events/
http://www.dev.opera.com/articles/view/简介-html5-video/
http://www.chipwreck.de/ blog/2010/02/23/html-5-video-test-area/
我认为应该是:
OP更正:
Check out these links:
http://www.chipwreck.de/blog/2010/03/01/html-5-video-dom-attributes-and-events/
http://www.dev.opera.com/articles/view/introduction-html5-video/
http://www.chipwreck.de/blog/2010/02/23/html-5-video-test-area/
I think it should be:
Correction by OP: