我正在为html5视频运行以下代码。
var media;
function videotr(){
media = document.createElement('video');
media.preload = true;
media.id = 'it';
document.getElementById('crop').appendChild(media)
return media;
}
var div = document.getElementById('crop');
$(div).empty();
this.image = new videotr();
this.image.src = args.src;但是,为了兼容,我想实现多个源。如何通过java脚本添加多个源码?我想用正确的方式来做这件事,而不是通过innerHtml。
发布于 2011-08-25 22:43:48
创建一个新的source元素并将其附加到video元素:
function addSourceToVideo(element, src, type) {
var source = document.createElement('source');
source.src = src;
source.type = type;
element.appendChild(source);
}
var video = document.createElement('video');
document.body.appendChild(video);
addSourceToVideo(video, 'http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv', 'video/ogg');
video.play();这是它的fiddle。
https://stackoverflow.com/questions/7192098
复制相似问题